'else' without a previous 'if'

Help me fix my else statement

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

int main()
{
string operation;
int userinput;
double total=0;
double num;
cout << "Welcome to Big People's Calculator"<< endl;
cout <<"" << endl;
//while ()
cout << "which operation would you like to use? (addition,subtract,multiply,divide)" << endl;
cin >> operation;
cout << "How many numbers would you like to use?" << endl;
cin >> userinput;

if (operation=="addition"||operation=="Addition"||operation=="ADDITION") {

for (int x=0;x<userinput;total=total+num ){
cout << "Please enter the number you would like to use" << endl;
cin >> num;
x++;
}
}

else if (operation=="subtract"||operation=="subtract"||operation=="SUBTRACT") {

for (int x=0;x<userinput;total=total-num ){
cout << "Please enter the number you would like to use" << endl;
cin >> num;
x++;
}
}

else if (operation=="multiply"||operation=="Multiply"||operation=="MULTIPLY") {

for (int x=0;x<userinput;total=total*num ){
cout << "Please enter the number you would like to use" << endl;
cin >> num;
x++;
}
}
else if (operation=="DIVIDE"||operation=="divide"||operation=="Divide") {

for (int x=0;x<userinput;total=total/num ){
cout << "Please enter the number you would like to use" << endl;
cin >> num;
x++;
}
}
cout << "This is your total " << total << endl;

else
{
cout << "You are not part of big people" << endl;
}
return 0;
}
Last edited on
Please format your code so we don't have to...

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
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
using namespace std;

int main()
{
string operation;
int userinput;
double total=0;
double num;
cout << "Welcome to Big People's Calculator"<< endl;
cout <<"" << endl;
//while ()
cout << "which operation would you like to use? (addition,subtract,multiply,divide)" << endl;
cin >> operation;
cout << "How many numbers would you like to use?" << endl;
cin >> userinput;

if (operation=="addition"||operation=="Addition"||operation=="ADDITION")
{
	for (int x=0;x<userinput;total=total+num )
	{
		cout << "Please enter the number you would like to use" << endl;
		cin >> num;
		x++;
	}
}

else if (operation=="subtract"||operation=="subtract"||operation=="SUBTRACT")
{
	for (int x=0;x<userinput;total=total-num )
	{
		cout << "Please enter the number you would like to use" << endl;
		cin >> num;
		x++;
	}
}

else if (operation=="multiply"||operation=="Multiply"||operation=="MULTIPLY") 
{
	for (int x=0;x<userinput;total=total*num )
	{
		cout << "Please enter the number you would like to use" << endl;
		cin >> num;
		x++;
	}
}
else if (operation=="DIVIDE"||operation=="divide"||operation=="Divide")
{
	for (int x=0;x<userinput;total=total/num )
	{
		cout << "Please enter the number you would like to use" << endl;
		cin >> num;
		x++;
	}
}
//cout << "This is your total " << total << endl;

else
{
cout << "You are not part of big people" << endl;
}

return 0;
}
Topic archived. No new replies allowed.