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
  • Write a program that reads k integers and displays their sum. Write a program that reads...

    Write a program that reads k integers and displays their sum. Write a program that reads k values representing family income from the keyboard and place them into the array. Find the maximum income among these values. Count the families that make less than 10 percent of the maximum income. (JAVA)

  • Write a function that takes an integer input n as a parameter and after it calculates...

    Write a function that takes an integer input n as a parameter and after it calculates the sum of 1+2+3+...+n, it returns the value to the main program. For example, if n=4, the output of the sum will be 10.

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • a. write a program that calculates the sum of two numbers x and y and then...

    a. write a program that calculates the sum of two numbers x and y and then the program should call the function by address and prints the sum b. write a program that stores 10 integers provided at run time in an array. the program should prompt the user for a random integer exit in the array, the value must be replaced by a-1

  • 1. Write a program that reads a sequence of numbers from the keyboard, and displays the...

    1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java

  • Write a C program which reads sets of two integers and displays them and their sum....

    Write a C program which reads sets of two integers and displays them and their sum. Continue readings sets of integers until their sum is zero, at which point terminate the program.

  • c++ Question 1 ram that calls a function calculateSum to calculate the sum from 0 to...

    c++ Question 1 ram that calls a function calculateSum to calculate the sum from 0 to N integers. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from 0 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float) The main function should be responsible for all inputs and outputs....

  • Write a program that first reads an integer for the array size, then reads double values...

    Write a program that first reads an integer for the array size, then reads double values into the array, and displays the number of values greater than the average. Enter array size: 6 Enter a number: 1.1 Enter a number: 2.2 Enter a number: 3.4 Enter a number: 3.9 Enter a number: 5.5 Enter a number: 8.75 The number of values greater than the average is 2

  • Task 1 : Write a Java program that prompts for and reads 10 integers from the...

    Task 1 : Write a Java program that prompts for and reads 10 integers from the user into an integer array of size 10, it then: - calculates the sum and average of positive numbers of the array and displays them. [Note: consider 0 as positive] Note: The program must display the message: "There are no positive values" if the array does not contain any positive value.

  • write a python program that allows the user to enter two integer values, and displays the...

    write a python program that allows the user to enter two integer values, and displays the results when each of the following arithmetic operators are applied

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