I'm writing a program that takes in input and formats it into a score as "Name Score".
Here is what needs to be done "Here's Moonglow's format. The text file is composed of words. If a word is a number, then that is a student's score on a question, so you add it to the student's exam score. If the word is not a number, but is the word "NAME", then the next word is the student's name (Moonglow only uses first names -- last names are corporate and impersonal). If the word is "AVERAGE", then you start reading numbers until you read a word that is not a number (or is the end of the file). You average all of those numbers and add that to the score. Since Moonglow is a little scatterbrained, sometimes a number does not follow "AVERAGE." In that case, you ignore the "AVERAGE". "
My problem is I've somehow entered into a infinite loop, and have spent hours trying to fix this. This is a VERY simple program, and I can't seem to get it to work!
while(!cin.eof())//while end-of-file character or sequence is NOT entered
do something: (Keep looping)....
and an inner loop
while (cin >> eScore)//while a double valid value is entered
do something(Keep looping):..
i.e.
outer while loop
./While
Enter number: 1
Number is: 1
Enter number: 3
Number is: 3
Enter number: 7
Number is: 7
Enter number: ^Z <-- EOF command (ctrl+D Mac OS X)
[2]+ Stopped ./While
//While.cpp
//##
#include <iostream>
usingnamespace std;
int main(){
int number;
while(!cin.eof()){
cout<<"Enter number: ";
cin>>number;
cout<<"Number is: "<<number<<endl;
}//end while
return 0; //indicates success
}//end of main
inner while
./While2
Enter number: 1
Enter number: 2
Enter number: 3
Enter number: 1
Enter number: Characters <-- not a double
Sum is: 7