I can't seem to figure it out...

Please help here is my code however I am not sure how to output text to a file and then use the file in the program below. The title of my file that I was attempting to write is included (people.txt) in the program, but I do not know how to correctly output the text so that it can be inputed in this program. Thank you guys.


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
30
31
32
33

#include <iostream>
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    int year, population;
    ifstream inputfile;
    int count;
    
    inputfile.open("People.txt");
    cout << "Prairieville Population Growth" << endl;
    cout << "(each * represents 1000 people)" << endl;
    cout << "Year  Population" << endl;
    year=1910;
    inputfile >> population;
    do {
        cout << year << "  " ;
        for(count=0;count<population;count+=1000) cout << '*';
        cout << endl;
        year+=20;
        inputfile >> population;
    } while (!inputfile.eof());
    inputfile.close();
    system("pause");
    return(0);
}


It is suppose to look like this... 





 Prairieville Population Growth
(each * represents 1000 people)
Year  Population

1910  **
1930  ****
1950  *****
1970  *********
1990  **************
2010  ******************

Press any key to continue . . .   

  Put the code you need help with here.
Last edited on
In line 19, you correctly read from the file inputfile>>population
writing(output to) is done in the same way. outputfile<<x
Topic archived. No new replies allowed.