creating a file & sending info to it

Write a program that reads from the keyboard, the number of point scored by the football team in each game. In the meantime, it also writes the entered scores into a file - scores.txt.
To begin with, the user doesn’t know the number of games played during the last season, hence, the agreed sentinel value between the user and the programmer is 7777. The program should stop reading the user’s input when a sentinel value is entered. Now, the program reads back the scores from the file, prints all the scores, prints the total number of points scored in the last season, and prints the average number of points scored (2 decimal points).

This is my assignment and i have no idea where to start
A nice tutorial for this kind of problem is on this site!

Below is that url:
http://www.cplusplus.com/doc/tutorial/files/

Here's how I learn a new functionality (especially with file processing):
Try with pre-generated file -> test code with that file.

Sort of like

Try it with a random file that has like:
Line 1: "I like trains!"
Line 2: "Hard to breathe"
Line 3: space

Read that link fully and if you get stuck ask a specific question about it and I or someone else on the form will be happy to help.

Have fun!

~ Hirokachi
ok so this is what i have so far, im not sure how to total up the points because there could be an infinite amount of games to total from

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 <fstream>
using namespace std;

int main()
{
	int game=1;
	int points=0;
	int total, average;
	
	ofstream outfile;
	ifstream infile;
	
	outfile.open("aggiescores.txt");
	while(points != 7777);
	{
		cout<<"Enter the number of points scored in Game "<<game<<":"<<endl;
		cout<<"Enter 7777 when you are done";
		cin>>points;
		outfile<<points;
		cout<<"Scores written into file …. aggiescores.txt";
		game++;
	}
	outfile.close();
	
	infile.open("aggiescores.txt");
	while ( infile >> points);       
	{        
		cout<<"Reading scores…";
		cout<<"Following are the scores from each game: "<<endl;
		cout<<points<<endl;
	}
	infile.close();
	cout<<"Aggies scored a total of "<<total<<" from "<<game<<" games and averaged at "<<average<<" points per game."; 
	
	return 0;
}
Topic archived. No new replies allowed.