Feb 20, 2016 at 10:54pm
I want to return the add value from the void function to the main and output the answer in the main. How would I do that?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include<iostream>
using namespace std;
void returning(float*, float*);
int main()
{
float num1 = 2;
float num2 = 7;
returning(&pnum1, &pnum2);
return 0;
}
void returning (float *num1, float*num2)
{
float add = *num1 + *num2;
}
|
Last edited on Feb 20, 2016 at 10:55pm
Feb 20, 2016 at 11:03pm
The easy way to is return a float from the function:
1 2 3 4 5
|
float returning (float *num1, float*num2)
{
float add = *num1 + *num2;
return add;
}
|
If the function mus return void, then change one of the args:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void returning(float*, float*);
int main()
{
float num1 = 2;
float num2 = 7;
returning(&num1, &num2);
std::cout << num1;
return 0;
}
void returning (float *num1, float*num2)
{
*num1 = *num1 + *num2;
}
|
Last edited on Feb 20, 2016 at 11:05pm