Dremendo Tag Line

Calculate average and check good or bad in C++

if else - Question 6

In this question, we will see how to input 5 decimal numbers and print good if their average is greater than 50, otherwise print bad in C++ programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q6) Write a program in C++ to input 5 decimal numbers and find their average. If the average is greater than 50 then print Good, otherwise print Bad.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    float a,b,c,d,e,avg;
    cout<<"Enter 5 decimal numbers\n";
    cin>>a>>b>>c>>d>>e;
    avg=(a+b+c+d+e)/5;
    cout<<"Average="<<avg<<endl;
    if(avg>50)
    {
        cout<<"Good";
    }
    else
    {
        cout<<"Bad";
    }
    return 0;
}

Output

Enter 5 decimal numbers
86.23
75.18
92.10
69.35
78.14
Average=80.2
Good
video-poster