It also might help if I tell you guys the whole program (*smh*...lol):
Ok...the bottom part of the program is supposed to read the file and then display the rounded number in a table as the charted population. I tried to redo the same piece as StuXYZ suggested but it didn't work, so I just left it. Here is what I have so far (sorry for the mix-up):
int main()
{
int people;
ifstream inputFile;
cout << "This program displays population by year.";
cout << endl;
cout << endl;
inputFile.open("people.dat");
if (!inputFile)
cout << "Error opening file." << endl;
else
{
for (int year = 1900; year < 2001; year += 20)
{
inputFile >> people;
cout << year << " ";
for (int star = 0; star < people / 1000; star++)
cout << '*';
cout << endl;
cout << endl;
}
}
inputFile.close();
inputFile.open("people.dat");
cout << "Year" << setw(20) << "Actual Population";
cout << setw(22) << "Charted Population" << endl;
cout << "----------------------------------------------";
cout << endl;
for (int year = 1900; year < 2001; year += 20)
{
inputFile >> people;
cout << year;
cout << setw(20) << people;
cout << setw(22) << people;
cout << endl;
}
system ("pause");
return 0;
}int main()
{
int people;
ifstream inputFile;
cout << "This program displays population by year.";
cout << endl;
cout << endl;
inputFile.open("people.dat");
if (!inputFile)
cout << "Error opening file." << endl;
else
{
for (int year = 1900; year < 2001; year += 20)
{
inputFile >> people;
cout << year << " ";
for (int star = 0; star < people / 1000; star++)
cout << '*';
cout << endl;
cout << endl;
}
}
inputFile.close();
inputFile.open("people.dat");
cout << "Year" << setw(20) << "Actual Population";
cout << setw(22) << "Charted Population" << endl;
cout << "----------------------------------------------";
cout << endl;
for (int year = 1900; year < 2001; year += 20)
{
inputFile >> people;
cout << year;
cout << setw(20) << people;
cout << setw(22) << people;
cout << endl;
}
system ("pause");
return 0;
}