Trying to make a function that returns a value

I'm trying to make a simple calculator that sends some values to a function and returns the value calculated. But I keep getting this error:
https://gyazo.com/bb56d32451828d211a4b4f057d5273d7
What does it mean and how can I fix it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
using namespace std;
int performOperation(int, string);


int main() 
{
   double numberOne, numberTwo;              	
   string operation;
   double result; 	
						
   cout << "Enter the first number: ";
   cin >> numberOne; 
   cout << "Enter the second number: ";
   cin >> numberTwo; 
   cout << "Enter an operator (+.-.*,/): ";
   cin >> operation;
		
   result = performOperation(operation, numberOne, numberTwo);

   cout << numberOne;
   cout << " " << operation << " ";
   cout << numberTwo;
   cout << " = ";
   cout << result << endl;
	
   return 0;
}
	
int performOperation(string operation, int numberOne, int numberTwo){
    int result;
    if(operation == "+"){
        result = numberOne + numberTwo;
    }
    if(operation == "-"){
        result = numberOne - numberTwo;
    }
    if(operation == "/"){
        result = numberOne / numberTwo;
    }
    if(operation == "*"){
        result = numberOne * numberTwo;
    }
    return result;
}
I can't click on the link you provided, but the obvious error is that your function prototype does not match your actual function.

Line 4 declares performOperation to take an int and a string,.

Line 20 is trying to call a function that takes a string and two int's but the compiler hasn't seen such a function.

One other problem. Line 45, if the operation is not one of the 4 you check for, you return an uninitialized variable.

In the future, please post your error messages here.
Last edited on
Thanks! I didn't know I had to write int two times. I used a link to share the error message because my editor doesn't allow me to copy it for some reason.
Topic archived. No new replies allowed.