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;
}
``````

Your code tags isn't structured properly.

Also, I'll give a hint. Work it out by hand first. Assume the first population is 755, for instance, and using what you know about the arithmetic operators, find a way to round to 1000. By finding it for this case, you can work out a general formula for any value. In addition, printing an asterisk per 1000 people is easier than rounding to the nearest thousand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.