I am having trouble trying to figure what goes into this forloop. I have a file
ID: 3609264 • Letter: I
Question
I am having trouble trying to figure what goes into this forloop.I have a file with 4 columns with the 1st columns a 9 digitnumber(num1), 2nd column a name(name), 3rd column a single digitnumber(dig1), and 4th column a 2 digit number(score).
I need to write a single for loop for:
to display name if the dig1 is = 4.
keep count of # of names with score >=70
keep count of total scores
check each score and see if it is highest, if so keep track of thatname.
I need to display some things(how many names had >=70 score,name with highest score, and avg score with 1 decimal). What I needhelp is the for loop. I know that before the for loop I have thefile opened and also a while loop:
(inFile >> num1 >> name >> dig1 >>score)
What goes in the () of the for loop? I am confused on what isinside of the parentheses. My code is:
ifstream inFile;
inFile.open("fileinput.txt");
string name;
int num1, dig1, score;
while(inFile >> num1 >> name >> dig1 >>score)
{
//for(.......)
//{
if(dig1==4)
cout << name<< " " << dig1 << endl;
while(score>=70)
}
I do not believe I need to use an if and while statement if I amusing the for loop. Little confused.
Explanation / Answer
please rate - thanks #include #include using namespace std; int main() { ifstream inFile; inFile.open("fileinput.txt"); long int num1; string name,hiname; int dig1, score,count=0,high=-3,records=0,total=0; inFile>>num1; while(inFile) {inFile>> name >> dig1 >> score; records++; if(dig1==4) coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.