Hi there, I have completed the program but I am having trouble with my output. It seems my "star" is outputting more more than 1 star than usual.
Question: Write a program that produces a bar chart showing the population growth of
Prairieville, a small town in the Midwest, at 20-year intervals during the past 100 years.
The program should read in the population figures (rounded to the nearest 1,000 people)
for 1900, 1920, 1940, 1960, 1980, and 2000 from a file. For each year it should display the date and a bar consisting of one asterisk for each 1,000 people. The data
can be found in the People.txt file.
Here is an example of how the chart might begin:
PRAIRIEVILLE POPULATION GROWTH
(each * represents 1,000 people)
1900 **
1920 ****
1940 *****
My Data Files which is named "Mitra.txt" contains the information:
1900 2230
1920 4899
1940 5783
1960 6466
1980 8222
2000 15248
Here is my code that is producing the problem. Thanks! Also sorry about the additional comments, I add that for my own sake to remember some stuff.
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
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream inputFile; // File stream object
inputFile.open("Mitra.txt");
int number;
int artesik;
int real;
for (int year = 1900; year <= 2000; year += 20)
{
cout << "For year: " << year << " ";
inputFile >> number >> real; // Because the file reads "1900 2565" this just reads the second number.
for (int i = 0; i <= real; i+=1000)
{
cout << "*";
}
cout << endl;
}
return 0;
}
|