I think I have a memory problem since this code keeps outputting large negative numbers. The file that it reads includes- lastname, firstname, identification number, then 5 decimal numbers. ZDoes anyone know what the problem is?
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const int rows = 5;
const int cols = 5;
int main()
{
ifstream inData;
string lastname, firstname;
int identity[5];
int number=0;
int i,j;
int subject;
float sum=0,total;
float numbers[rows][cols];
inData.open("data.txt");
while (inData)
{
inData>>lastname>>firstname>>identity[number];
for (i=0; i<rows; i++)
{
cout<<lastname<<" "<<setw(2)<<firstname<<" "<<identity[number]<<" ";
for (j=0; j<cols; j++)
{
inData >> numbers[i][j];
cout<<fixed<<setprecision(1)<<setw(5)<<numbers[i][j]<<" ";
sum=sum+numbers[i][j];
}
cout<<setw(5)<<sum/8;
sum=0;
cout<<endl;
}
cout<<endl;
}
inData.close();
return 0;
}