C++ multiply function help

Im new cpp learner im trying to create a multiply function to multiply 3 numbers variables, when i want to compile it , it gives me an error in the line 12, i dont know whats missed in this line , any help is much appreciated





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 #include <iostream>
using namespace std;
void Multiply( int n1, int n2, int n3) 
{
cout<<n1*n2*n3;
}
int main( )
{
int num1, num2, num3;
cout << "Enter three integers: ";
cin >> num1 >> num2 >> num3;
cout<<Multiply(num1, num2, num3);
return 0;
}
hey, multiply is a void function, so cout cannot do anything with it (line 12).
you can make it return a value:

int mul(int a, int b, int c)
{return a*b*c;} //note my function does not print anything. you can do that when you call it.

and then because mul returns an integer, and cout knows what to do with an integer, it will work.
or you can leave it be and let your function do the printing, and remove the line 12.

you can return any type from a function, but cout does not understand every type (esp some user defined types). Later you may learn how to make a type AND set it up so cout can use it, but that can wait for another day. just be aware for now that void functions and some other types do not always have support for printing, so those things cannot be printed without a bit more work.
Last edited on
Thank u for reply, i understand now! Thank us so much for ur help , really appreciate it
Topic archived. No new replies allowed.