I have no idea what is wrong with this

When it compiles i get no errorss but it doesnt output for some reason help please!

#include <iostream>
#include <cmath>
using namespace std;


int add(int a, int b){
int answer;
answer = a + b;
return answer;
}
int subtract(int a, int b){
int answer;
answer = a - b;
return answer;
}

int main()
{
int a;
int b;
int option;
cout << "What is your first number?" << endl;
cin >> a;
cout << "What is your second number?" << endl;
cin >> b;
cout << "What will your option be, subtract or add?" << endl;
cin >> option;
if (option == 'add'){
cout << add(a, b);
}
if (option == 'subtract'){
cout << subtract(a, b);}

return 0;
}

You defined 'option' as an integer however you are expecting answers like 'add' and 'subtract'. That is not going to work as integer variables are only able to hold whole numbers.

Change int option to string Option so that it can hold words (You will also need to use double quotes around add,subtract instead of single quotes, as they aren't chars). Don't forget to include #include <string> at the top of your file as well.
then your code should look like this:
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
#include <iostream>
#include <math.h>
#include <string>
#include <cmath>
using namespace std;


int add(int a, int b){
	return a+b;
}

int subtract(int a, int b){
	return a-b;
}

int main()
{
	int a;
	int b;
	string option;
	cout << "What is your first number?" << endl;
	cin >> a;
	cout << "What is your second number?" << endl;
	cin >> b;
	cout << "What will your option be, subtract or add?" << endl;
	cin >> option;

	if (option == "add") {
		cout << add(a,b)<<endl;
	}

	if (option == "subtract") {
		cout << subtract(a,b)<<endl;
	}

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.