Why won't this compile?

I'm trying to write a basic code but I can't get it to compile, it's giving me "cout" errors. The code is below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Example program
#include <iostream>
#include <string>
using namespace std;
void fu(int&a, int&b, int c);
int main()
{
int x=11;
int y=5;
cout<<fu(x,y,19);
}
void fu(int&a, int&b, int c){
    c=a*b;
    if(a%b){
        a=c+a%b;
    }
}
What are you trying to print? fu is a void function which means it doesn't return a value.
cout << fu(x,y,19); is asking the program to print the output from fu when there isn't any.
Last edited on
fu does not return a value, but you're trying to output its return value anyway.
I wish to return x,y, and z. the question was stated such The call fu(x, y, z) is issued, where x, y & z are all int variables with values of 11, 5 and 19 respectively. What are the values of x, y and z after the call is made?

1
2
3
4
5
6
void fu(int&a, int&b, int c){
    c=a*b;
    if(a%b){
        a=c+a%b;
    }
}


The answer is x=56, y=51, and z=19 but I can't get them to print.

I updated my code, I can get one number to print now but not all 3 at once.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int fu(int&a, int&b, int c);
int main()
{
int x=11;
int y=5;
cout<<fu(x,y,19);
return 0;
}
int fu(int&a, int&b, int c){
    c=a*b;
    if(a%b){
        a=c+a%b;
        return a;
      
    }
}
Last edited on
just remove the cout on line 9 and add it before line 10 something like cout << x << ' ' << y << endl;
Thank you I got it working.
Topic archived. No new replies allowed.