Hi ive been searching google for quite some while now and i cant figure out how to use the function getFile to return the whole file back into the main function.
it just returns the last integer when i run it. please help! assignment is due tonight.
heres the original question for a heads up.
Using functional decomposition, design and write a C++ program that inputs a series of 24 hourly temperatures
from a file, and you will create your own input data file with necessary data for your test cases. You will output
a bar chart (using stars) of the temperatures for the day. The temperature should be printed to the left of the
corresponding bar, and there should be a heading that gives the scale of the chart. The range of temperatures
should be from –30 to 120. Because it is hard to display 150 characters on the screen, you should have each star
represent a range of 3 degrees. That way, the bars will be at most 50 characters wide. Here is a partial
example, showing the heading, the output for a negative temperature, and the output for various positive
temperatures. Note how the temperatures are rounded to the appropriate of stars
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 36 37
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void getFile(int &num);
int main()
{
int num;
getFile(num);
cout << num;
system ("PAUSE");
return 0;
}
void getFile(int &num)
{
ifstream inFile;
inFile.open("C:\\Users\\Peter\\Documents\\CSP31A\\Assignment3question2.txt");
if(!inFile){
cout << "\nOpen file song.dat not successful";
}
inFile >> num;
while (inFile >> num){
cout << num;
cout << endl;
}
}
|