Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Description Using your IDE of choice, write a simple program that asks the user for a count of how many numbers will be input,

Program Description

Using your IDE of choice, write a simple program that asks the user for a count of how many numbers will be input, then inputs that many integers, adds them up, and calculates the average. It must contain two functions as described below. The best solution to the problem will use separate compilation units.

You must write a function getValue that is used to input each number and verifies that it is within the range 1 to 99 and return it to the calling program. If the input value is outside that range, tell the user and ask them to enter a new value. Likewise, check for non-numbers, tell the user invalid input and ask for a new value.

You must also use a single function doCalc to perform the processing and provide both the average and total to the main.

main should look like this

prompt the user to enter the number of values get the number of values to be entered (using getValue)

call doCalc to read in that many values, sum them, and return the total and average

display the total and average

doCalc should look like this

for each number (from 1 up to the number of values)

get the value (it must be validated)

add the value to the total

end for loop

calculate the average

your two functions should be

getValue: takes no parameters and returns a int

doCalc: takes the number of values (int) as its first parameter and uses 2 reference parameters to "return" the total (int) and average (double).

This is what i have but i need help with the doCalc to take the number of values (int) as its first parameter and uses 2 reference parameters to "return" the total (int) and average (double).

My current code:

#include using namespace std; int getValue() { int n; bool ok; do{ cin>>n; //If n in inrange then return it if(n>0 && n<100) { ok = true; return n; } else { //If n is out of range then ask user to input again cout << "Invalid, Enter number in range (1 to 100): "; ok = false; } } while (!n>0 && n<100); } pair doCalc(int n) { double sum=0; //pair pair output; cout<<"Enter the values"< output = doCalc(n); cout<<"Sum: "<                        

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions