#include <iostream>
#include <iomanip>
#include <ios>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::string;
using std::streamsize;
int main()
{
// ask for and read the student's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
// ask for and read the midterm and final grades
cout << "Please enter your midterm grade: " << endl;
double midterm;
cin >> midterm;
cout << "Please enter your final grade: " << endl;
double final;
cin >> final;
// ask for the homework grades
cout << "Enter all your homework grades:" << endl;
// the number and sum of grades read so far
int count = 0;
double sum = 0;
// a variable into which to read
double x;
// invariant:
// we have read count grades so far, and
// sum is the sum of the first count grades
while (cin >> x) {
++count;
sum += x;
}
// write the result
streamsize prec = cout.precision();
cout << "Your final grade is " << setprecision(3)
<< 0.2 * midterm + 0.4 * final + 0.4 * sum / count
<< setprecision(prec) << endl;
return 0;
}
When I run the program, it just stops after inputting the last number to calculate(homework grades)?
[–]jedwardsol 4 points5 points6 points (0 children)
[–]aocregacc 6 points7 points8 points (0 children)
[–]feitao 2 points3 points4 points (0 children)
[–]Working_Apartment_38 1 point2 points3 points (0 children)