looping help

I am currently working on an assignment for my cs1 class and I would just like some help on figuring out how to set up a loop system. I need to create a console app to calculate student grades. I figured out how to create a file and input info and then close the file, but I don't want to have to keep typing the same information over and over when I can set up a loop system to make it easier. please help guide me along to at least come close to setting it up. I would much appreciate it.
So far this is what I have:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void main()
{
	ofstream outfile;
	outfile.open("C:/Users/Ben/My Documents/students.txt");
	string lastName, firstName, lastName2, firstName2;
	cout << "Please type in the first student's last name: ";
	cin >> lastName;
	outfile << lastName << ", ";
	cout << "Please type in the first student's first name: ";
	cin >> firstName;
	outfile << firstName << ": ";
	float score11, score12, score13, score21, score22, score23;
	cout << "Please type in the the first student's first score: ";
	cin >> score11;
	cout << "Please type in the the first student's second score: ";
	cin >> score12;
	cout << "Please type in the the first student's third score: ";
	cin >> score13;
	float avg, result;
	avg = score11 + score12 + score13;
	result = avg / 3;
	cout << "The first student's name and average score is: " << firstName << " " << lastName << ": " << result << endl;
	outfile << result << endl;
	cout << "Please type in the second student's last name: ";
	cin >> lastName2;
	outfile << lastName2 << ", ";
	cout << "Please type in the second student's first name: ";
	cin >> firstName2;
	outfile << firstName2 << ": ";
	cout << "Please type in the the second student's first score: ";
	cin >> score21;
	cout << "Please type in the the second student's second score: ";
	cin >> score22;
	cout << "Please type in the the second student's third score: ";
	cin >> score23;
	float avg2, result2;
	avg2 = score21 + score22 + score23;
	result2 = avg2 / 3;
	outfile << result2 << endl;
	cout << "The second student's name and average score is: " << firstName2 << " " << lastName2 << ": " << result2 << endl;
	outfile.close();
	char ch;
	cin >> ch;
}
Looks like you've got a slightly different assignment than was in this other thread, but there's a for loop for entering grades there. Does that help at all?

http://www.cplusplus.com/forum/beginner/124499/#msg676570
kinda, but i need a loop for entering student names.
when you open the .txt document, it should read:
Last name, First name: Average grade
So something likeā€¦

while the user has more student names and grades to enter (start loop)
- collect name data
- collect grade info (accumulate into one bucket unless you specifically need to keep separate grades for a student?)
- calculate average and output it to screen
- write data to file
- ask if more grades are to be entered (if no, exit loop, close file)


actually yes lol
Topic archived. No new replies allowed.