-->





find minimum maximum and average c++ program

Simple c++ program which takes input numbers from user and find minimum, maximum and average of numbers
Program uses do while loop to find min, max and avg. 
User can input many numbers, condition is set for -1 to get results. You can set any number according to your wish.
To calculate user has to break do while loop condition which breaks when user inputs -1.


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    float max=0.0,min=0.0,sum=0.0;
    float num=0.0;
    float avg=0.0;
    cout<<"enter a whole number or -1 to get result:";             //program working through example
    cin>>num;                                  
    max=num;                                   
    min=num;                                  
    do
    {
    if(num!=-1){
        sum=sum+num;        
        if(num>max)                 
        max=num;                        
        else
        if(num<min)                    
        min=num;                           
        cout<<"enter a whole number or -1 to get result:";             
        cin>>num;                          
      }
    }
    while(num!=-1);                      
        avg=sum/10.0;
        cout<<"sum="<<sum<<endl;
        cout<<"average of numbers you entered is:"<<avg<<endl;
        cout<<"maximum number you enter is:"<<max<<endl;
        cout<<"minimum number you enter is:"<<min<<endl;
        getch();
        }


program output:
find min max number c++ code

find more examples here: c++ programming examples and solutions
find sample c++ projects here: c++ projects source codes

This example will help the beginner to refresh logic building muscle. 
It is recommended to practice these kinds of codes. Sometimes while programming our mind hesitate for some complex code and before going enough deep to understand and implement a good logic our mind return us back. 
Doing these code practices will make your logic building ability fresh and when a complex problem needs to solve your mind will give you positive energy. Yes go, deep dive into it you can do it.!!

0 comments:

Post a Comment