I am having an issue reading from a file in a c++ problem. Please find my code below and tell me what you think. I keep on getting "File open failure!"
Problem:
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 tot he nearest 1000 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 1000 people. For example, let's use 3000, 7000,10000, 25000, 29000 and 30000.
Here is an example of how the chart might begin:
PRAIRIEVILLE POPULATION GROWTH
(each * represents 1000 people)
1900 ***
1920 *******
1940 **********
// main.cpp
// Population Chart
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int year,population;
ifstream inputFile;
inputFile.open("People.txt");
//if (inputFile.fail())
if(!inputFile)
{
cout << "File open failure!";
}
cout << "PRAIRIEVILLE POPULATION GROWTH\n" <<endl;
cout << "(each * represents 1000 people)\n" <<endl;
while (inputFile >> population)
{
for (year =1900 ; year<=2020; year += 20)
{
cout<< year;
for (int i = 1; i <= population/1000; i++)
{
cout<<"*";
}
cout<< endl;
}
}
inputFile.close();
return 0;
}