Nov 4, 2016 at 1:35am UTC
With Rows = 5, Cols = 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
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 54 55 56 57
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
cout << "Kaitlin Stevers" << endl;
cout << "Exercise 9A - Arrays" << endl;
cout << "October 31, 2016" <<endl;
const int ROWS = 5;
const int COLS = 5;
float numbers[ROWS][COLS];
ifstream inputFile;
inputFile.open("Ex9data.txt" );
for (int countRows = 0; countRows < ROWS; countRows++)
{
for (int countColumns = 0; countColumns < COLS; countColumns++)
{
inputFile >> numbers[countRows][countColumns];
}
}
inputFile.close();
int i, j;
float sumCols;
float sumRows;
float sumRowsTotal = 0;
for (i = 0; i < ROWS; i++)
{
sumCols = 0;
for (j = 0; j < COLS; j++)
{
cout << numbers[i][j] << ' ' ;
sumCols += numbers[i][j];
}
cout << "| " << sumCols;
cout << endl;
}
for (i = 0; i < COLS; i++)
{
sumRows = 0;
for (j = 0; j < ROWS; j++)
{
sumRows += numbers[j][i];
}
sumRowsTotal += sumRows;
cout << sumRows << ' ' ;
}
cout << "| " << sumRowsTotal << endl;
return 0;
}
Kaitlin Stevers
Exercise 9A - Arrays
October 31, 2016
1 2 3 4 5 | 15
1 2 3 4 5 | 15
1 2 3 4 5 | 15
1 2 3 4 5 | 15
1 2 3 4 5 | 15
5 10 15 20 25 | 75
Press any key to continue
Edit : Farewell, your account is closed so hopefully this is my last help.
Last edited on Nov 4, 2016 at 1:36am UTC
Nov 4, 2016 at 1:36am UTC
Apparently the person above can't read. I'm sorry you are having to deal with them. Also I ran their code and got a bazaar output.
Last edited on Nov 4, 2016 at 1:38am UTC
Nov 4, 2016 at 1:42am UTC
No. I'm messaging them. When I ran your code I got this: Kaitlin Stevers
Exercise 9A - Arrays
October 31, 2016
3.11457e+12 4.59163e-41 3.11457e+12 4.59163e-41 3.11458e+12 | 9.34373e+12
4.59163e-41 5.34205e-32 1.4013e-45 0 1.4013e-45 | 5.34205e-32
1.10456e-28 1.4013e-45 1.10455e-28 1.4013e-45 0 | 2.20911e-28
0 0 0 0 0 | 0
0 0 0 0 3.11458e+12 | 3.11458e+12
3.11457e+12 5.34205e-32 3.11457e+12 4.59177e-41 6.22916e+12 | 1.24583e+13
Nov 4, 2016 at 1:46am UTC
I did... Maybe it's because I'm using an iMac. I've had trouble before with txt documents... Let me try it in ubuntu.. brb. BTW i sent you a message sakuraouBusters
Last edited on Nov 4, 2016 at 1:51am UTC