why doesn't the file reading statement in the code below return "Harry" & "Houdini"? It seems that, based on the info I have found, it should return the 1st 2 words.
......CODE......
//
// main.cpp
// GradeCalculator
//
// Created by Andrew on 6/4/13.
//
//
using namespace std;
//--------build structure
struct Grade
{
string StudentName;
int NoOfHomeWorkGrades;
double HomeworkGPA;
double HomeworkWeight;
int NoOfProjectGrades;
double ProjectGPA;
double ProjectWeight;
int NoOfExamGrades;
double ExamWeight;
double ExamGPA;
double TotalGPA;
char LetterGrade;
string Comment;
}GradeStructure;
//----------function declarations
void GetInFileName(string&);
void GetOutFileName(string&);
int ReadFile(double&);
string GetComment(char&);
void GetLetterGrade(double&);
int OpenInFile(ifstream&);
int OpenOutFile(ofstream&);
//string GetOutFileName(string&);
int WriteData(char&, string&);
int CalculateGrade();
//-----------Main Body
int main()
{
double TotalGPA;
ifstream InDataFile;
ofstream OutDataFile;
string InFileName;
string OutFileName;
string Quote;
//char LetterGrade;
cout << "Welcome to the GradeCaculator Deluxe." << endl;
ReadFile(TotalGPA);
GetLetterGrade(TotalGPA);//this function calls "GetComment()"
//WriteData(LetterGrade, Quote);
//---------create structure--------------------
//system ("pause");
return 0;
}//end main
//-----------GetFileName
//-----------Get file name to read from
void GetInFileName(string& InFileName)
{
cout << "Enter the name of the file to gather info from (including extension): ";
cin >> InFileName;
//reference variables do not need a return
}//end GetInFileName
//----------GetOutFileName
//----------Get name of output file
void GetOutFileName(string& OutFileName)
{
cout << "Enter the name of the file to write info to (including extension): ";
cin >> OutFileName;
}//end GetOutFileName
//----------OpenInFile
//----------open the user specified file to read from
int OpenInFile(ifstream& InDataFile)
{
string InFileName;
GetInFileName(InFileName);
InDataFile.open(InFileName.c_str());
if (!InDataFile)
{
cout << "File Failed to open...Program terminated" << endl;
return 1;
}//end if
//ReadFile(TotalGPA);
return 0;
}//end OpenInFile
int OpenOutFile(ofstream& OutDataFile)
{
string OutFileName;
GetOutFileName(OutFileName);
OutDataFile.open(OutFileName.c_str());
if (!OutDataFile)
{
cout << "File Failed to open...Program terminated" << endl;
return 1;
}//end if
//ReadFile(TotalGPA);
return 0;
}//end OpenInFile
//---------ReadFile
//---------read the user specified file
int ReadFile (double& TotalGPA)
{
ifstream InDataFile;
int RowNumber;
string FirstName;
string LastName;
int StudentId;
int NoOfClasses;
string Grade;
//float TotalPtsAllowed;
int index;
//float TotalScore;
//int Grades;
//double Weight;
//double Average;
int Assignments[3];
//int GradeArray[50];
//double WeightArray[3];
//----------CalculateGrade
//----------perform Grade Calcualtions
int CalculateGrade()
{
int Weight;
int Grade;
int TotalScore;
int TotalPtsAllowed;
Grade=(TotalScore / TotalPtsAllowed) * Weight;
return Grade;
Harry Houdini 1212 3 MAG101 A PRES201 A ESC301 A
Henry Ford 2211 2 MFG110 A SAL202 B
Albert Einstein 1155 1 CALC100 F
Alan Turing 9082 4 CSC110 A CSC201 A CSC210 A CSC205 A
Melvil Dewey 1876 2 LIBM102 C SUPV202
ok, thanks for the help. trying to read it and understand it. I get the following error....."[ERROR] range-based for loops are not allowed in c++98 mode"
thanks, that did the trick. Can you give me a brief explanation as to how this works? I see that you created a structure....understand...I figured out what the double colon does.....understand (which is pretty cool)......but I'm not really sure what the for loop means with the colon in it. so I'm not really sure why your code captures the whole word and mine didn't....
I really appreciate you helping this old dog learn some new tricks.
for( const student& s : students ) // for each student 's' in the vector students
{
// ...
for( const student::grade& g : s.grades ) // for each grade 'g' in the vector s.grades
{
// ...
}
}