30713 4 3 3 4 3 3 2 3 4 3 21356 4 4 4 3 3 3 2 3 2 3 21265 4 1.5 3 3 3 0.5 2 3 3 3 19364 4 3 3 3 -1 -1 -1 -1 -1 -1 19335 0 3 0 4 2 3 3 1.5 -1 -1 18264 2 3 3 0.5 3 0.5 3 3 2 3 20135 4 1 3 4 3 1.5 0 3 -1 -1 22185 4 3 4 4 4 3 3 3 4 3
And this is the main code...I'm trying to read the grade and credit hours in each course as you can see. There are spots where there are no courses taken, so I put -1 in the place of them. What loop can I put inside my while loop so when the sentinel value of -1 is read, the inside loop IN the while loop stops and goes to the next line in the input data file?? Thanks
P.S. (Where i put in the IF statement, it may be wrong. I was still trying to work on it.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <stdlib.h>
using namespace std;
//function prototypes go
//double findGPA(double points, double hours);
int main()
{
double gpa, points, hours, ID, grade, crhrs;
ofstream OutputFile;
OutputFile.open("Output.dat");
ifstream infile;
infile.open("Input.dat");
OutputFile<<setw(30)<<"Thomas Powe"<<endl;
OutputFile<<setw(29)<<"03-27-12"<<endl<<endl;
OutputFile<<setw(15)<<"ID"<<setw(18)<<"GPA"<<endl<<endl;
infile>>ID>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs;
while (!infile.eof())
{
if (grade <= -1 || crhrs <= -1)
{
break;
}
//infile>>ID>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs;
//OutputFile<<setw(15)<<ID<<setw(18)<<"Comin Soon"<<endl;
points = (grade * crhrs) + (grade * crhrs); //+ //(grade * crhrs); //+ (grade * crhrs) + (grade * crhrs);
hours=crhrs + crhrs; //+ crhrs +crhrs +crhrs;
gpa=points/hours;
infile>>ID>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs;
OutputFile<<setw(15)<<ID<<setw(18)<<gpa<<endl;
}
OutputFile.close();
infile.close();
return 0;
}
//Function Definitions go here
//double findGPA(double points, double hours)
//{
//return gpa;
//}
//
This is supposed to be the output code
Your Name
03-27-2012
ID GPA
30713 3.2
21356 3.1
21265 2.9
19364 3.5
19335 0.9
18264 2.4
20135 2.2
22185 3.8

New Topic/Question
Reply



MultiQuote





|