Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////////////////
- //
- // Name: Crystal Ballin
- // Date: 3/20/18
- // Class: CMPE 1370.02
- // Semester: Spring 2018
- // CSCI/CMPE 1370 Instructor: Gustavo Dietrich
- //
- // Use a sentinal controlled do ... while loop to find the average of
- // grades entered by the user. The sentinal value is -1.
- //
- //////////////////////////////////////////////////////////////////////
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- int grade; // The grade entered by the user
- int sum=0; // Sum of the grades
- int count=0; // Number of grades entered
- double avg=0; // Average of the grades
- ////////////////////////////////
- // Start of your code
- // Use a do .. while loop to loop until the user enters -1
- // Each time through the loop, add the number input by the user
- // to the sum. Make sure not to include the sentinal value in the
- // sum or count!
- do
- {
- cout << "Enter a grade, or a -1 to stop: ";
- cin >> grade;
- sum+= grade;
- count++;
- }
- while (grade != -1);
- {
- }
- // Find the average of the grades entered by the user
- // and print the result
- avg = (static_cast<double>(sum) / (static_cast<double>(count)));
- //avg = static_cast<double>(sum / count);
- cout << fixed << setprecision(1);
- cout << "The average is: " << avg << endl;
- // End of your code
- ////////////////////////////////
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement