Question

Write a template for a function called total. The function should keep running total of values entered by the user, then return the total. The argument sent into the function should be the number of values the function is to read. Test the template in a simple driver program that sends values of various types as arguments and displays the results.

How many integer values do you wish to total? Enter a value: 5 1 Enter a value: 2 Enter a value: 3 Enter a value: 4 Enter a v

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
 *  C++ Program to total the integers
 */

#include <iostream>
using namespace std;

void  total(int num)
{
  double n, sum = 0;

  for (int i = 1; i <= num; i++)
  {
    cout << "Enter a value: ";
    cin >> n;
    sum += n;
  }
  cout << "The total is " << sum;
}

int main()
{
  int num;

  cout << "How many integer values do you wish to total?  ";
  cin >> num;
  total(num);

  cout << endl << endl;
  
  cout << "How many double values do you wish to total?  ";
  cin >> num;
  total(num);
  
  return 0;
}

= @ Gimtusharsharma/MedicalKnowingWebportal No description invite 9 run share + new repl main.cpp B saved Press F11 lo exil f

Add a comment
Know the answer?
Add Answer to:
Write a template for a function called total. The function should keep running total of values...
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 templates for the two functions minimum and maximum. The minimum function should accept two arguments...

    Write templates for the two functions minimum and maximum. The minimum function should accept two arguments and return the value of the argument that is the lesser of the two. The maximum function should accept two arguments and return the value of the argument that is the greater of the two. Test your functions in a main program that propmts the user to choose what type of data they would like to compare (ints, doubles, or strings). Then, it should...

  • Design a function named max that accepts two integer values as arguments and returns the value...

    Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...

  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

    Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...

  • dev c+ Write the function called simplicity, which makes the denominator and denominator values of the...

    dev c+ Write the function called simplicity, which makes the denominator and denominator values of the simple fraction sent to it as simple as possible, together with a main function where the denominator and denominator information are entered from the keyboard. Print the values of variables that hold the numerator and denominator values entered from the keyboard before sending them to the function and their changed states after they are sent to the screen. (The global variable should not be...

  • in C++. Write a function squareRoot that uses the Newton’s method of approximate calcu-lation of the...

    in C++. Write a function squareRoot that uses the Newton’s method of approximate calcu-lation of the square root of a number x. The Newton’s method guesses the square root in iterations. The first guess is x/2. In each iteration the guess is improved using ((guess + x/guess) / 2 ) as the next guess. Your main program should prompt the user for the value to find the square root of (x) and how close the final guess should be to...

  • c++ programming please. thx. Define a function template named "merge" to merge two lists of items...

    c++ programming please. thx. Define a function template named "merge" to merge two lists of items into one list including all the items of the first list followed by the items of the second list. Even though, the data type of the items of the lists is a generic type, both input lists include items of the same type. To merge the two lists, the function first dynamically allocates enough memory to accommodate the items of both lists. The allocated...

  • %%Python Question%% get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should...

    %%Python Question%% get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should be a positive number) ◦ the annual interest rate (should be a float between 0 and 1) ◦ the term of the mortgage, in years (should be a positive integer; default value: 30) ◦ the number of payments per year (should be a positive integer; default value: 12) • Functionality ◦ Compute the minimum mortgage payment. Should use the formula A= Pr(1+r) n (1+r)...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

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