Question

Write a program that reads two integer values. It then calculates and displays the sum and average of all values between them, Le. if the first value is vi and the second value is 2, then the program calculates and displays the sum and average of all values in the closed range Iv1,2 Your Program must satisfy the following constraints: A. make sure that v1 is less than 2 B. Use a function named getStats(that takes two integer yalues as parameters and returns two outputs: the sum and average of all values from the first parameter to the second parameter inclusive Hint: to write a function that returns more than one output, use references. A Sample example is shown in figure below. Note that if v1 is greater than v2, the program will not accept them asking for another two values (validation). nter Two Integer Values: 125 nter Two Integer Values: 3 1 The sum of all values in 13, 101: 52 The avg of all values in [3, 101: 6.5 ress any key to continue.. .
0 0
Add a comment Improve this question Transcribed image text
Answer #1

_________________

#include <iostream>

#include <iomanip>

using namespace std;

//function declarations

void getStats(int v1,int v2,int &sum,double &avg);

int main()

{

//Declaring variables

int v1,v2;

int sum=0;

double avg=0.0;

  

/* This while loop continues to execute

* until the user enters a valid numbers

*/

while(true)

{

//Getting the input entered by the user

cout<<"Enter two integer values :";

cin>>v1>>v2;

if(v1<v2)

{

break;

}

}

//calling the function

getStats(v1,v2,sum,avg);

//Displaying the output

cout<<"The sum of all values in ["<<v1<<","<<v2<<"]:"<<sum<<endl;

Note: Could you plz go thls code and let me know If u need any changes In this.Thank You #include <iostream> #include <iomanip> using namespace std /function declarations void getStats(int vi,int v2,int&sum,double &avg): int main /Declaring variables int v1,v2 int sum-0; double avg 0.0 / This while loop continues to execute *until the user enters a valid numbers 치 while(true) //Getting the input entered by the user

Add a comment
Know the answer?
Add Answer to:
Write a program that reads two integer values. It then calculates and displays the sum and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT