Hello, I'm having trouble with my array assignment. The instructions are
Create a integer type two-dimensional array of 4 rows and 3 columns
Populate the two-dimensional array with values entered by the user, use a function for this.
Print the array in a spreadsheet format, also print the sum of the values of each row. The out put must be:
Row Totals
value01 value02 value03 Sum01
value04 value05 value06 Sum02
value07 value08 value09 Sum03
value10 value11 value12 Sum04
The column's values and Sums must be right justified. Use the setw() function.
Use a function to print the values. Call this function printValues().
Must use loops to enter values, traverse the array, calculate sum, and print the values in the array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include<iostream>
#include<iomanip>
using namespace std;
int const ROWS = 3;
int const COLUMNS = 4;
void userInputValue();
void printValues();
int main()
{
userInputValue();
printValues();
return 0;
}
void userInputValue()
{
int index = 0;
int myArray[ROWS][COLUMNS];
cout << "Enter 12 numbers" << endl;
for(int row = 0; row < ROWS; row++)
{
for(int column = 0; column < COLUMNS; column++)
{
cout << ++index << ". Enter a number: ";
cin >> myArray[row][column];
}
}
} // End of method userInputValue
void printValues()
{
int myArray[ROWS][COLUMNS];
cout << "The numbers you entered were:" << endl;
for(int row = 0; row < ROWS; row++)
{
for(int column = 0; column < COLUMNS; column++)
{
cout << myArray[row][column] << ' ';
cout << endl;
}
}
} // End of method printValues
|
SO far this is what I have and whenever it prints I get
"Row Totals
0
1
2 "
Edit; The "row totals" must be on top of the sums section not on top of the values.