Programming Challenge Chapter 3 – Q #3 Test Average – Tony Gaddis – Starting Out With C++
Problem: -
Solution: -
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
float num1, num2, num3, num4, num5;
float average = 0;
cout << "Enter First Number:
";
cin >> num1;
cout << "Enter Second Number:
";
cin >> num2;
cout << "Enter Third Number:
";
cin >> num3;
cout << "Enter Four Number:
";
cin >> num4;
cout << "Enter Fifth Number:
";
cin >> num5;
average = (num1 + num2 + num3 + num4 + num5)/5.0;
cout << setprecision(1) << fixed << showpoint;
cout << "Average is " << average;
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Input is highlighted with yellow color.
Explanation of this Solution
- Declare five float variables for user input.
- Declare another one float variable for average calculation.
- Take first number input from the user by using cin.
- Take second number input from the user by using cin.
- Take third number input from the user by using cin.
- Take fourth number input from the user by using cin.
- Take fifth number input from the user by using cin.
- Calculate average of five numbers.
- Use setprecision for one decimal notation.
- In last, display Average output on the screen.
- Return 0 to the main function.
Also, I attach CPP file of this problem. You can download this file
0 Comments