Write a program that determines the average of 3 integers. The program should ca
ID: 3624799 • Letter: W
Question
Write a program that determines the average of 3 integers.The program should call a function to get the values from
the user.
The signature for that function should be:
void getNumbers(int& n1, int& n2, int& n3)
Once the input is gotten it should call another function to
determine the average. That function should return the average
back to the calling function (main).
The function signature should be:
double getAverage(int n1, int n2, int n3);
Note that it returns a double (not an int).
In order to force the double result of the
average calculation, do: avg = sum / 3.0;
Where avg is a double. sum is an int. The
3.0 forces the resulting average to a double
value.
Back in main then display the average
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
void getNumbers(int& n1, int& n2, int& n3);
double getAverage(int n1, int n2, int n3);
int main()
{int n1,n2,n3;
double average;
getNumbers(n1,n2,n3);
average=getAverage(n1,n2,n3);
cout<<"the average of "<<n1<<", "<<n2<<" and "<<n3<<" is "<<average<<endl;
system("pause");
return 0;
}
void getNumbers(int& n1, int& n2, int& n3)
{cout<<"Enter number 1: ";
cin>>n1;
cout<<"Enter number 2: ";
cin>>n2;
cout<<"Enter number 3: ";
cin>>n3;
}
double getAverage(int n1, int n2, int n3)
{return (n1+n2+n3)/3.;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.