Answer to Question #259032 in C++ for Charmaine

Question #259032

Write a program that loads several numbers from the keyboard,

asking in the meantime, the question "Do you want to finish: Y / N?"

At the end of the loop, program should display calculated values of:

the arithmetic averagemaximumminimum of given numbers.


1
Expert's answer
2021-10-30T11:21:49-0400
#include <iostream>


using namespace std;


int main()
{
    int arr[100];
    int n=0;
    cout<<"\nEnter several numbers: ";
    while(true){
        int num;
        cin>>num;
        arr[n]=num;
        char c;
        cout<<"\nDo you want to finish: Y / N?";
        cin>>c;
        if (c=='Y'){
            break;
        }
        n++;
    }
    
    int min=arr[0];
    int max=arr[0];
    int sum=0;
    for(int i=0;i<n;i++){
        if(arr[i]>max)
            max=arr[i];
        if(arr[i]<min)
            min=arr[i];
        sum+=arr[i];
    }
    
    cout<<"\nMaximum number: "<<max;
    cout<<"\nMinimum number: "<<min;
    cout<<"\nAverage number: "<<(sum/n);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS