124k views
3 votes
Write three functions, float getNum(), float add(float, float), void outSum(float); that asks user for two numbers, finds the sum of two numbers, and displays the sum repeatly in a main program until the user enter “0” for either one of the numbers. For example, in the main, user enter 2, 4, output sum is 6. Then, 3,7, sum is 10, then 8, 7, sum is 15. When user enter one 0, the repeating process stops.C++ language only. No points will be given if other languages are used.

********************************
I have already written some code but I do not know where I am going wrong.
#include
using namespace std;
float getNum (float& x, float& y);
float add (float& x, float& y, float& z);
void outSum (float& z);



int main ()
{

float NumberOne = 0;
float NumberTwo = 0;
float Total = 0;


float getNum[2] = (NumberOne)(NumberTwo);
float add (NumberOne, NumberTwo, Total);
void outSum (Total);





}




float getNum (float& x, float& y)

{
cout << "Enter number one " << endl;
cin >> x;
cout << "Enter number two " << endl;
cin >> y;




}


float add (float& x, float& y, float& z) {
z = x + y;

}

void outSum (float& z) {

cout << "The total is " << z << endl << endl;

}

User Ozeray
by
5.3k points

2 Answers

7 votes

Answer:

#include <iostream>

float getNum()

{

float num;

std::cout << "Enter a number: ";

std::cin >> num;

return num;

}

float add(float num1, float num2)

{

return num1 + num2;

}

void outSum(float sum)

{

std::cout << "The sum of the two numbers is: " << sum << std::endl;

}

int main()

{

float num1, num2, sum;

while (true)

{

num1 = getNum();

num2 = getNum();

if (num1 == 0 || num2 == 0)

{

break;

}

sum = add(num1, num2);

outSum(sum);

}

return 0;

}

User Twistedpixel
by
5.8k points
0 votes

Answer:

#include <iostream>

using namespace std;

float getNum()

{

float num;

cout << "Enter a number: ";

cin >> num;

return num;

}

float add(float num1, float num2)

{

return num1 + num2;

}

void outSum(float sum)

{

cout << "Sum is " << sum << endl;

}

int main()

{

float num1, num2, sum;

num1 = getNum();

num2 = getNum();

while (num1 != 0 && num2 != 0)

{

sum = add(num1, num2);

outSum(sum);

num1 = getNum();

num2 = getNum();

}

return 0;

}

User Nghauran
by
5.7k points