1. ## Please review and comment

Problem:
Program allows the user to enter grade information for up to 20
students in a class.
For each student, first calculate a final grade , using the formula:
finalgrade = 0.20 * Exam 1 + 0.20 * Exam 2 + 0.35 * Homework + 0.25 * Final Exam
then, assign a letter grade on the basis of 90-100=A, 80-89=B, 70-79=c,
60-69=d, less than 60=F.
All the information, including the final grade and the letter grade should be
written and displayed to a file.
Note: Program should STOP after 20 loops. Ask the user if they want to continue?
If the counter < 20, prompt the user, store - Ex. - enter a y to continue or an n
to quit. You can use a do-while loop condition such as: while counter less than 20
and proceed equal to 'Y'

Question for you: How would you handle the exit condition?

Code:

#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{
const int MAXSTUDENTS = 20;
const int MAXNAME = 20;
const int MAXCHARS = 10;
int i;
float exam1, exam2, homework, finalexam, finalgrade;
ofstream outFile;

outFile.open(firstname);
if (outFile.fail())
{
cout << "\nNot successful opening " << firstname << endl;
exit(l);
}
outFile << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
for (i = 1; 1 <= MAXSTUDENTS; i++)
{
cout << "\nEnter the student's last name: ";
cin >> lastname;
cout << "\nEnter exam 1's grade: ";
cin >> exam1;
cout << "\nEnter exam 2's grade: ";
cin >> exam2;
cout << "\nEnter the student's homework grade: ";
cin >> homework;
cout << "\nEnter the final exam grade: ";
cin >> finalexam;

finalgrade = 0.20 * examl + 0.20 * exam2 + 0.35 * homework + 0.25 * finalexam;

cout << lastname << " " << examl << " " << exam2 << " " homework
<< " " << finalexam << " " << finalgrade << " " << lettergrade << endl;
outFile << lastname << " " << examl << " " << exam2 << " " homework
<< " " << finalexam << " " << finalgrade << " " << lettergrade << endl;
}

return 0
}

2. #include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{
top:
const int MAXSTUDENTS = 20;
const int MAXNAME = 20;
const int MAXCHARS = 10;
int i;
//Char Quit
char quit;
float exam1, exam2, homework, finalexam, finalgrade;
ofstream outFile;

outFile.open(firstname);
if (outFile.fail())
{
cout << "\nNot successful opening " << firstname << endl;
exit(l);
}
outFile << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
//for(i=1; 1 ....) should be
for (i = 1; i <= MAXSTUDENTS; i++)
{
cout << "\nEnter the student's last name: ";
cin >> lastname;
cout << "\nEnter exam 1's grade: ";
cin >> exam1;
cout << "\nEnter exam 2's grade: ";
cin >> exam2;
cout << "\nEnter the student's homework grade: ";
cin >> homework;
cout << "\nEnter the final exam grade: ";
cin >> finalexam;

finalgrade = 0.20 * examl + 0.20 * exam2 + 0.35 * homework + 0.25 * finalexam;

cout << lastname << " " << examl << " " << exam2 << " " homework
<< " " << finalexam << " " << finalgrade << " " << lettergrade << endl;
outFile << lastname << " " << examl << " " << exam2 << " " homework
<< " " << finalexam << " " << finalgrade << " " << lettergrade << endl;
if(i == 20)
{
cout << "Quit? [ Y ]-yes [ N ]- no" << endl;
cin>>quit;
switch(quit)
{
case y:
case Y: return 0;
break;
case n:
case N: goto top;
}
return 0
}

try something like that....and use the [ code ] tags w/o the spaces

3. Code tags people!

And, I'd avoid using 'goto', if I were you. It can lead to problems diagnosing bugs, and harder to maintain code. A more conventional loop construct would be better.

4. GOTOs ARE EVIL!!

Or at least that's what my professors have told me for four years... The reason we have loops and conditionals is so we don't need gotos.

Anyway, this is how I do programs like this. First of all, since the problem asked for up to twenty students, I would use a while loop, although you could use a for loop and break out of it if they want to quit before 20 students.

Code:
```#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{
const int MAXSTUDENTS = 20;
const int MAXNAME = 20;
const int MAXCHARS = 10;
int i;
float exam1, exam2, homework, finalexam, finalgrade;
ofstream outFile;

char quit;  // I'll steal gcn_zelda's variable name!
int count;  // Number of students so far

outFile.open(firstname);
if (outFile.fail())
{
cout << "\nNot successful opening " << firstname << endl;
exit(l);
}
outFile << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);

count = 0;
quit = 'n';
while ((count < 20) && (quit == 'n'))
{
cout << "\nEnter the student's last name: ";
cin >> lastname;
cout << "\nEnter exam 1's grade: ";
cin >> exam1;
cout << "\nEnter exam 2's grade: ";
cin >> exam2;
cout << "\nEnter the student's homework grade: ";
cin >> homework;
cout << "\nEnter the final exam grade: ";
cin >> finalexam;

finalgrade = 0.20 * examl + 0.20 * exam2 + 0.35 * homework + 0.25 * finalexam;

cout << lastname << " " << examl << " " << exam2 << " " homework
<< " " << finalexam << " " << finalgrade << " " << lettergrade << endl;
outFile << lastname << " " << examl << " " << exam2 << " " homework
<< " " << finalexam << " " << finalgrade << " " << lettergrade << endl;

// Before exiting the loop, prompt the user if they want to continue.
// To avoid making the user enter 'y' a lot of times, you could say
// "Enter student's first name or 'N' to quit", or something like that.
// (Of course then it would make more sense to have them enter 'Q'!)
cout << "Continue? (y or n): ";
cin >> quit;
cout << endl;
++count;  // Don't forget to increment count!

}

outFile.close();  // ALWAYS close your files when you're done!!!

return 0;

}```
You would also have to make the user enter a lowercase 'n' or you could convert their entry to lowercase (or uppercase, whatever you like) so you don't have to check both possibilities.

(Edited for formatting)

5. ## Tsk tsk tsk...

>> #include <fstream.h>
>> #include <iomanip.h>
>> #include <stdlib.h>

You're using the old standard headers. You should use <fstream>, <iomanip>, and <cstdlib>, which are standard and use the std namespace.

6. Oops, XSquared is right. Since this is obviously an intro to C++ kind of program, have you learned about the std namespace and the "using" statement? If not, it would be good to look it up since that's now standard C++ programming.