Answer to Question #186097 in C++ for Ricky

Question #186097

Write a C++ program that will accept three integers and return the average value of these integers. Make use of array num[ ] in your program.



1
Expert's answer
2021-04-27T05:23:32-0400
#include <bits/stdc++.h>
using namespace std;


int main()
{
    int n, i;
    float num[100], sum=0.0, average;


    cout << "How many numbers are you going to enter? ";
    cin >> n;


    while (n > 100 || n <= 0)
    {
        cout << "Error! number should in range of (1 to 100)." << endl;
        cout << "Enter the number again: ";
        cin >> n;
    }


    for(i = 0; i < n; ++i)
    {
        cout << i + 1 << ". Enter a number: ";
        cin >> num[i];
        sum += num[i];
    }


    average = sum / n;
    cout << "Average = " << average;


    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