Reputation: 21
Hello everyone I am sure someone can help me out I am very new to c++ trying to make this program work. When I get to call my int function from my main function it tells me that it has not been declared. I used a prototype on top so I am not sure why it is hanging up. Also am I missing any syntax? Thanks for your help in advance.
#include <iostream>
using namespace std;
int multiFunction(int, int, char);
int main()
{
int value1, value2, OP, total;
total = multifunction(value1, value2);
cout << "Enter a simple math problem I will solve it for you:";
cin >> value1 >> OP >> value2; //gets the three values
cout << "The answer is: " << total << end //displays the answer
return 0;
}
int multiFunction(int A, int B, char OP)
{
int C; //Holds the integer after the operation.
switch(OP)
{
case '+':
C = A + B;
break;
case '-':
C = A - B;
break;
case '*':
C = A * B;
break;
case '/':
C = A / B;
}
return C;
}
Upvotes: 1
Views: 64
Reputation: 17
The main function should be:
int main()
{
int value1, value2, total;
char OP;
cout << "Enter a simple math problem I will solve it for you:";
cin >> value1 >> OP >> value2; //gets the three values
total = multiFunction(value1, value2, OP);
// ^^
cout << "The answer is: " << total << end //displays the answer
return 0;
}
Upvotes: 1
Reputation: 1367
Spell Error:
total = multifunction(value1, value2);
should be:
total = multiFunction(value1, value2, OP);
Upvotes: 1
Reputation: 22821
You are not passing the third parameter here:
total = multifunction(value1, value2); //Prototype is int multiFunction(int, int, char);
Also multifunction
is not the same as multiFunction
.
int a
and int A
are 2 unique variables. Similar rules go for methods.
Upvotes: 5