Answer to Question #309327 in C++ for Harry

Question #309327

In the main function, define four variables of type int, named: first, second, third, and total.

Write a function named getData that asks the user to input three integers and stores them in the variables first, second, and third which are in the main function.

Write a function named computeTotal that computes and returns the total of three integers.

Write a function named printAll that prints all the values in the format shown in the following sample:

1 + 2 + 3 = 6
  

Call the other three functions from the main function.

Test it once, with the values 4, 5, and 6.



1
Expert's answer
2022-03-10T18:07:13-0500
#include <iostream>

using namespace std;

void getData(int &first, int &second, int &third)
{
	cout << "Please, enter a value of first: ";
	cin >> first;
	cout << "Please, enter a value of second: ";
	cin >> second;
	cout << "Please, enter a value of third: ";
	cin >> third;
}

int ComputeTotal(int &first, int &second, int &third)
{
	return first+second+ third;
}

void printAll(int &first, int &second, int &third, int &total)
{
	cout << first << " + " << second << " + " << third << " = " << total;
}

int main()
{
	int first, second, third, total;
	getData(first, second, third);
	total= ComputeTotal(first, second, third);
	printAll(first, second, third, total);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog