Looping Help
Feb 11, 2013 at 3:26pm UTC
For this program i had to change and input file and make a output file showing the name grades and averages of 20 students> I can't seem to figure out to get it to loop. Im only getting the first name and can't get the rest of the names and grades to show up. Can anyone give any pointers or provide help?
-----------------
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
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
infile.open( "student1.txt" );
outfile.open ("Names Grades.txt" );
int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;
int num8;
int num9;
int num10;
double avg = 0;
string lastName, firstName;
double total = 0;
while (infile >> lastName >> firstName >> num1>> num2>> num3>> num4>> num5>>num6>>num7>>num8>>num9>>num10);
{
total = num1+num2+num3+num4+num5+num6+num7+num8+num9+num10;
avg = total / 10;
if (total < 0);
{
cout << lastName << "," << " " << firstName << ":" <<" " << num1 << " " << num2 << " " << num3 << " " <<num4 << " " << num5 << " " << num6 << " " << num7 << " " << num8 << " " <<num9 << " " <<num10 <<" " << avg << "\n" ;
outfile <<lastName << ", " <<" " << firstName << ":" << num1 << " " << num2 << " " << num3 << " " <<num4 << " " << num5 << " " << num6 << " " << num7 << " " << num8 << " " <<num9 << " " <<num10 <<" " << avg << "\n" ;
}
}
return 0;
}
Feb 11, 2013 at 3:27pm UTC
on line 30: remove the ;
at the end of the line
Feb 11, 2013 at 3:33pm UTC
THANK YOU~! I'm such an idiot...
Feb 11, 2013 at 3:43pm UTC
well, i guess everyone stepped at least once in this trap
Topic archived. No new replies allowed.