Need Help Please!!

i'm asking to : " Write a program for entering test scores and calculating results of the scores. The
scores should be saved in a file. Here is how the program should look when it is run.

The program should use file streams – ifstream and ofstream – for its file IO.

(Sample run. User input is shown in bolb)


Welcome to the test scores program!
What do you wish to do? 1 = create file 2 = read file 3 = quit
1
Enter filename:
scores.txt
Enter a series of scores, with -1 to stop
10.5 9.5 10 12 -1
What do you wish to do? 1 = create file 2 = read file 3 = quit
2
Enter filename:
scores2.txt
Error - could not open scores2.txt
What do you wish to do? 1 = create file 2 = read file 3 = quit
2
Enter filename:
scores.txt
Total of scores = 42
Average is 10.5
What do you wish to do? 1 = create file 2 = read file 3 = quit
3
ok, goodbye!
Last edited on
Show us your code.
@One in a million

Also, you should NOT double post.
http://www.cplusplus.com/forum/beginner/201115/

It becomes a waste for the helpers.

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

using namespace std;

void makefile(string filename)
{
ofstream outfile;
outfile.open(filename);
if (!outfile) // if failed to open
{
cout << "Error - could not open " << filename<< endl;
return;
}
cout << "Enter a series of numbers, and a -1 to stop the data entry\n";
while (true)
{
int i;
cin >> i;
if (i == -1)
break;
outfile << i << endl;
}
outfile.close();
}

void readfile(string filename)
{
ifstream infile;
infile.open(filename);
if (!infile)
{
cout << "Error - could not open " << filename << endl;
}

double total = 0;
int i;
while (infile >> i)
{
total += i;
cout << "reading " << i << endl;
}
cout << "total = " << total << endl;
}

int main()
{

makefile("scores.txt");
readfile("scores.txt");

system("pause");
}




This is what i have so far


@whitenite sorry for the double post, i'm so new in here
Topic archived. No new replies allowed.