Need help with my C++ code

I can't figure out what is wrong with my code at case 3. I have posted the output I'm getting below when I choose option 3 from the menu I created.




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
34
35
case 3: 

cout << "Population Bar Chart" << endl;
cout << "--------------------" << endl;
cout << endl;
cout << endl;
cout << "This is what is inside the file for People.txt" << endl;
inputFile.open("People.txt");
if (inputFile)
{
for (int x = 0; x < 7; x++)
(inputFile, Popnum[7]);
cout << Popnum[7] << endl;
}

cout << "Prairieville Population Growth" << endl;
cout << "Every * equals 1000" << endl;
cout << "-------------------" << endl;

for (int x = 0; x + 1 < 7; x++, Time +=20)
{

cout << "Year " << Time << ": ";
for (int i = 0; Popnum[i] / 1000 > i; i++)
{
cout << "*";
}
cout << endl;
}
inputFile.close();

break;
} 
return 0;
}










This is my output currently:

Choose from the menu, which part of the program you wish to run. Type 1, 2, or 3 :
1. Sales Bar Chart
2. Sales Bar Chart with Files
3. Population Bar Chart

3
You have chosen: 3!

Population Bar Chart
--------------------


This is what is inside the file for People.txt
4.88906e-270
Prairieville Population Growth
Every * equals 1000
-------------------
Year 1900: *
Year 1920: *
Year 1940: *
Year 1960: *
Year 1980: *
Year 2000: *
1
2
3
4
5
6
7
8
9
10
11
if (inputFile)
{
for (int x = 0; x < 7; x++) 
(inputFile, Popnum[7]); /// only this line is performed by the for loop. If you want
                        /// more than one statement you need to put braces around them
                        /// this statement actually does nothing. Missing getline??
                        /// Popnum[7] should perhaps be Popnum[x]. PopNum[7] is out of range
                        /// The syntax Popnum[7] doesn't mean the whole array it means the eighth element of the array

cout << Popnum[7] << endl;
}



This is what is inside the file for People.txt
4.88906e-270  /// because the cout is not part of for loop you print only Popnum[7]
              /// you didn't put anything in Popnum[7] so it prints out whatever junk is in memory.
Prairieville Population Growth
Every * equals 1000
-------------------
Year 1900: *
Year 1920: *
Year 1940: *
Year 1960: *
Year 1980: *
Year 2000: *
Last edited on
What are you trying to do on line 12? My guess is that Popnum is not correctly populated. If it has length 7, Popnum[7] should not be defined. Compiles should flag it as error. If it more than 7 in length, and not initialized, Popnum[i] might get initialized to zero. That Popnum[7] that you print is close enough to 0. If all are 0, you should get only one star on each line
Topic archived. No new replies allowed.