Question

C++ problem: Write a function that: accepts three integers as it's only arguments computes the average...

C++ problem:

Write a function that:

  • accepts three integers as it's only arguments
  • computes the average of the arguments
  • returns the average without loss of precision
  • does not use global variables
  • does not interact with the user in any way

Homework Answers

Answer #1

double average(int n1, int n2, int n3) {
    return (n1 + n2 + n3) / 3.0;
}

#include <iostream>

using namespace std;

double average(int n1, int n2, int n3);

int main() {
    int n1, n2, n3;
    cout << "Enter three integers: ";
    cin >> n1 >> n2 >> n3;
    cout << "Average is " << average(n1, n2, n3) << endl;
    return 0;
}

double average(int n1, int n2, int n3) {
    return (n1 + n2 + n3) / 3.0;
}

Know the answer?
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
Similar Questions
C++ problem: Write a function that: accepts two integer variable arguments by reference swaps the contents...
C++ problem: Write a function that: accepts two integer variable arguments by reference swaps the contents of the two variables does not return anything does not interact with the user in anyway
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the range [0-100] as input from the user. Your program should then determine and print the smallest and largest integers in the values entered by the user using comparison operators *not* using predefined min or max Python functions. For instance: If the user input is: 36 5 99 your program should give as output: min = 5 max = 99 If the user input is:...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b,...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b, c, and then computes the results of the following logical operations, in sequence: !a || !b++ && c (a-1 || b/2) && (c*=2) (a-- || --b) && (c+=2) a || !(b && --c)
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens the file for reading Reads an integer from the file and returns it. Create a main function that Asks the user to input a file Passes that file to the “ReadFile” function Prints the returned integer to the screen Extra Credit: Set a default argument of “intfile.txt” for the “ReadFile” function Write an overloaded function of “ReadFile” that accepts two filenames and reads an...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens the file for reading Reads an integer from the file and returns it. Create a main function that Asks the user to input a file Passes that file to the “ReadFile” function Prints the returned integer to the screen
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
PLEASE DO IT IN C++ ONLY. THE MIN-MAX DIGIT PROBLEM Write a function named minMaxDigit() that...
PLEASE DO IT IN C++ ONLY. THE MIN-MAX DIGIT PROBLEM Write a function named minMaxDigit() that accepts an integer as an input parameter and returns the largest and smallest digits using the two output parameters min and max. For example, the call minMaxDigit(68437, min, max) would set min to 3 and max to 8. If there is only one digit, then both min and max are set to the same value. The function has no return statement.
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...