I made this program that asks users to enter the grade of some students, determine whether they pass or fail and then determine how many pass and how many fail the exam. Here's my code:
#include <iostream>
usingnamespace std;
int main ()
{
int passing = 0;
int failing = 0;
int mid_grade;
int final_grade;
int student = 5;
while (student > 0)
{
cout << "Enter mid-term grade: ";
cin >> mid_grade;
cout << "Enter final grade: ";
cin >> final_grade;
double total_grade = (double)mid_grade*3/10 + (double)final_grade*7/10;;
cout << "The total grade is: " << total_grade << endl;
student --;
if (mid_grade < 4 || final_grade < 4 || total_grade < 10)
{
// cout << "Fail." << endl;
failing++;
}
else
{
// cout << "Pass!" << endl;
passing++;
}
}
cout << passing << " student passed" << endl;
cout << failing << " student failed" << endl;
return 0;
}
what I want to do now is to tell my program to read the mid-term and the final grade in a text file I made then calculate the total grade (like I did in the above code), then show the grades on the screen, determine who pass and fail the exam and the total number of students who pass/fail the exam.
Here's what my text file looks like:
1 2 3 4 5 6 7
Mid-term Final
8 5
9 6
10 11
15 17
9 20
11 19
Please help me with this problem. Thanks in advance.
Spend 15 minutes and read this tutorial.
http://www.cplusplus.com/doc/tutorial/files/
You will need to either get your program to ignore line 1 of your data file, or delete it before you start using it ( the simpler of the two unless you've been told it has to be there).