Hi, what I am trying to do in this program is to save the numbers enter by the user into the array data but with any positive result. This is what I got so far. Thanks for any help.
Code:
#include <iostream> #include <iomanip> using namespace std; void printHeading(); int main() { cout<<endl; char choice; int rows=5; int columns=5; int array[5][5]={{2,13,23,45,50}, {5,12,34,36,51}, {2,23,25,46,54}, {2,7,35,39,48}, {3,5,26,39,49}}; int newArray[5]; printHeading(); for(int i=0; i<rows; i++) { cout<<setw(33)<< i <<")"; for(int j=0; j<columns; j++) { cout<<setw(8)<<array[i][j]; } cout<<endl; } do { cout<<"\n Enter 5 numbers: "; for(int i=0; i< 5; i++) { cin>>newArray[i]; } cout<<endl; printHeading(); for(int i=0; i<rows; i++) { cout<<setw(33)<< i <<")"; for(int j=0; j<columns; j++) { newArray[ array[i][j] ]=array[i][j]; // saving the array data into the newArray cout<<setw(8)<<newArray[ array[i][j] ]; } cout<<endl; } cout<<"\n\n Would you like to try again? (y/n): "; cin >> choice; } while (choice == 'y'|| choice == 'Y'); cout<<endl; return 0; } void printHeading() { cout<<setw(82)<<"=====================================================\n\n"; cout<<setw(76)<<"ROWS (0) (1) (2) (3) (4)\n"; cout<<setw(81)<<"-----------------------------------------------------\n"; }
Comment