Hi this is tetsu here
I need a little help regarding input and output. I am trying to write a program to read information from a text file as long as there is names and numbers next to them (test score numbers). For each name read, a sequence of test scores is read, but stops reading when it hits a negative number. When it stop at the negative numbers it will calculate the numbers it read so far in to an average number. Well Im stuck at the negative number and getting how many numbers there is. I read the <fstream> Tutorials but I still dont understand it.
Well this is what I have now, it isnt much.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
string avgtext = "Your average is ";
string grade = "and your letter grade is ";
int main()
{
int score1 = int();
int score2 = int();
int score3 = int();
int score4 = int();
int score5 = int();
int i = int();
string fName = string();
string lName = string();
ifstream inFile;
inFile.open("c:\\input.txt");
inFile >> fName >> lName >> score1 >> score2;
cout << "Your Name is : " + fName << " " << lName << endl;
cout << "Your scores are : " << score1 << " " << score2 << " ";
cout << score3 << " " << score4 << " " << score5 << endl;
for(int i=0; i<5; ++i)
while(i<2)
{
inFile >> fName >> lName >> score1 >> score2 >> score3 >> score4 >> score5;
++i;
}
/*
if (x > 90)
{
cout << avgtext << x << grade << "A" << endl;
}
else if (x > 80 && x <= 90)
{
cout << avgtext << x << grade << "B" << endl;
}
else if (x > 67.5 && x <= 80)
{
cout << avgtext << x << grade << "C" << endl;
}
else if (x > 55 && x <= 67.5)
{
cout << avgtext << x << grade << "D" << endl;
}
else (x >= 0 && x <= 55)
{
cout << avgtext << x << grade << "F" << endl;
}*/
inFile.close();
return 0;
}
text file
Tetsu Itou 84 73 83 -3
Mimi Itou 87 76 90 -70 65