Else statement not working

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
48
49
50
51
52
53
54
55
56
57
    int main(){
	unsigned int fstNumb = 0, sndNumb = 0;
	cout << "Choose the first number: ";
	cin >> fstNumb;
	cout << "\nChoose the second number: ";
	cin >> sndNumb;
	cout << "\nNow click \'m\' to multiply, \'a\' to add or \'d\' to divide: ";
	char option = '\0';
	cin >> option; cout << "\n\n";
	float result;
	if (option == 'm'){
		result = fstNumb * sndNumb;
		cout << result;
	} 
	else if (option == 'a'){
		result = fstNumb + sndNumb;
		cout << result;
	}
	else if (option == 'd') {
		if (fstNumb == 0 || sndNumb == 0)
			cout << "Cannot divide with 0 :/";
		else {
			cout << "You want the " << fstNumb << " or " << sndNumb << " to be divided?\n";
			cout << "Press 1 for " << fstNumb << " or 2 for " << sndNumb;
			short option2;
			cin >> option2;
			if (option2 == 1){
				cout << "\nYou chose " << fstNumb;
				cout << "\nWanna divide it by how much?: ";
				unsigned short division;
				cin >> division;
				if (division == 0){
					cout << "\nCannot divide by 0!";
				}
				else{
					result = fstNumb / division;
				}
			}
			else if (option2 == 2){
				cout << "\nYou chose " << sndNumb;
				cout << "\nWanna divide it by how much?: ";
				unsigned short division;
				cin >> division;
				if (division == 0){
					cout << "\nCannot divide by 0!";
				}
				else{
					result = sndNumb / division;
				}
			}
			else
				cout << "You must choose one of those 2 numbers!\n";
		}
	}
	else
		cout << "That's none of the letters I asked you.\n";
}


The else's in this code, specifically in line 27 to 48 are not working, what's wrong? The only thing it does is check if the division variable is 0, if it's not it's supposed to display the result. I don't get it why it's wrong...

Thanks in advance.
Last edited on
Runs ok for me, what do you see?
Its not that its not working...its not displaying the results because no where is a line that tells the program to print out the result....Look at line 36 you define result but you do not tell the program to print it...
Sometimes I can be really dumb ._. Damn.

Thanks.
Topic archived. No new replies allowed.