0

Here's the problem:

Write a program that produces a bar chart show 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 1000 people) for 1900, 1920, 1940, 1960, 1980, 2000 from a file. for each year it should display the date and a bar consisting of one asterisk for each 1000 people.

My problem is how to round the imputed number to the nearest 1000 and after that how do i store the asterisk per 1000 people in a line in the file.

```
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string round(double);
int main()
{
string display, func;
ofstream PBC;
double pop;
PBC.open("C:\\Users\\sandman\\desktop\\People.txt");
cout << "What was the population of 1900 rounded to the nearest 1000? " << endl;
cin >> pop;
func = round(pop);
func;
PBC << "1900. " << func << endl;
cout << "What was the population of 1920 rounded to the nearest 1000? " << endl;
cin >> pop;
func;
PBC << "1920. " << func << endl;
cout << "What was the population of 1940 rounded to the nearest 1000? " << endl;
cin >> pop;
func;
PBC << "1940. " << func << endl;
cout << "What was the population of 1960 rounded to the nearest 1000? " << endl;
cin >> pop;
func;
PBC << "1960. " << func << endl;
cout << "What is the population of 1980 rounded to the nearest 1000? " << endl;
cin >> pop;
func;
PBC << "1980. " << func << endl;
cout << "What is the population of 2000 rounded to the nearest 1000? " << endl;
cin >> pop;
func;
PBC << "2000. " << func << endl;
PBC.close();
ifstream PBCo;
PBCo.open("C:\\Users\\sandman\\desktop\\People.txt");
while(PBCo >> display ){
cout << display << endl;}
PBCo.close();
system("pause");
return 0;
}
string round (double pop)
{
string ast;
double count = 0;
ast = "*";
while (count != pop){
count = count + 1000;
ast = ast + "*";}
return ast;
}
```

*Edited 3 Years Ago by Nick Evan*: Fixed formatting