Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please read everything before answering! My Assignment: (1) Generate a data file

ID: 3639566 • Letter: P

Question

Please read everything before answering!

My Assignment:
(1) Generate a data file to record students' grades. Allow users to enter file name of data file; id, name and grade for each student as well as the total number of students. A header should be shown in the data file as follows. Here is an example of the data file.

ID NAME GRADE

01 Mary 100.00
02 Tom 98.35
03 John 88.99
......

(2) If the grade is <0 or >100, ask users to re-enter the correct grade.
(3) After the data file is generated, read the file and print the content to the screen.

My Question:
I am having trouble getting the loop to continue without conditions. When I ask the users to enter the total number of students, it stops after the required information is given. Please don't just write the code for me. I need to understand what I am missing and why. Here is what I have so far:


#include<iostream>
#include<fstream>
#include<string>

using namespace std;


int main()
{

int ID, x;
double Grade;

cout<<"Please use this program to generate a data file to record students' grades."<<endl<<endl;

string filename;
string Name;

ofstream fout;
ifstream fin;

fout.open("test.dat");
cout<<"Please enter file name."<<endl;
cin>>filename;
fout.open(filename.c_str());

cout<<"Please enter total number of students you wish to record data for."<<endl;
cin>>x;
while (x<=0)
{
cout<<"Invalid data. Please try again."<<endl;
system("pause");
return 0;
}

cout<<"Please enter ID, Name, and Grade of the student."<<endl;
cout<<"Hit enter between entering information to be able to distinguish between."<<endl;
cin>>ID>>Name>>Grade;
cout<<"ID Name Grade"<<endl;

while (Grade<0 || Grade>100)
{
cout<<"Invalid data:"<<Grade<<endl;
cout<<"Please try again."<<endl;
system("pause");
return 0;
}


system("pause");

return 0;

}

Explanation / Answer

With the line while (total
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote