![]() |
| | #1 |
| Registered User Join Date: Mar 2006
Posts: 36
| Storing and printing matrices Code: #include <iostream>
#include <iomanip>
using namespace std;
const int numrow = 3;
const int numcol = 4;
int grades [numrow][numcol];
int main ()
{
for (int i = 0; i <= 3; i++)
{
cout << endl;
for (int j = 0; j <= 4; j++)
{
cout << "enter grades for row # " << (i + 1)<< ": ";
cin >> grades [numrow][numcol];
}
}
cout << setw (4) << grades [i][j];
return 0;
}
|
| stevedawg85 is offline | |
| | #2 |
| Ethernal Noob Join Date: Nov 2001
Posts: 1,891
| 1) you should have the for loop control variables set to numrow and num col (i < numrow) (j < numcol) - (not i <= numrow since the last indice will always be one less than the size) - so you don't have to go back and change them when you change the size of the array 2) Code: cin >> grades [numrow][numcol]; 3) Your'e outputting the Grades[i][j] outisde of the scope of where i and j were declared. You'd have to do another loop to output it. Here's what I got. Code: #include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
const int numrow = 3;
const int numcol = 4;
int grades [numrow][numcol];
for (int i = 0; i < numrow; i++)
{
cout << endl;
for (int j = 0; j < numcol; j++)
{
cout << "enter grades for row # " << (i + 1) << ": ";
cin >> grades [i][j];
}
}
for (int i = 0; i < numrow; i++)
{
cout << endl;
for (int j = 0; j < numcol; j++)
{
cout << setw(4) << grades[i][j];
}
}
cout << endl;
system("PAUSE");
return 0;
}
Last edited by indigo0086; 03-20-2006 at 09:05 AM. |
| indigo0086 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Opening a file and then printing the output? | Sholcomb1 | C Programming | 5 | 11-02-2006 09:44 AM |
| Help with Printing BMPs | simtron | Windows Programming | 5 | 09-22-2005 09:21 AM |
| Storing in structure | bennyboy | C Programming | 1 | 02-26-2005 06:14 AM |
| Problem with storing and printing | kasun | C++ Programming | 2 | 02-25-2004 08:36 AM |
| integers storing as symbols in arrays | rjcarmo | C++ Programming | 4 | 05-19-2003 01:17 AM |