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.
#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);
}
Comments
Leave a comment