If statements error

I continue to get the C2181 error from VS. The message is "illegal else without if" My stepfather, a software engineer, and I cannot seem to find the issue. Any assistance would be greatly appreciated

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  #include <iostream>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	string typeHorse;
	int weightHorse;
	double weight;
	float poundsFood;

	//Calc Table

	cout << "\nErin's Horse Stable";
	cout << "\n________________________________________________________________________________";
	cout << "\nHorse Type				Minimum Optimum Weight       Maximum Optimum Weight";
	cout << "\n________________________________________________________________________________";
	cout << "\n 1. Light Riding Horse     840                            1200";
	cout << "\n 2. Large Riding Horse     1110							 1300";
	cout << "\n 3. Draft Horse            1500						     2200";
	cout << "\n________________________________________________________________________________";

	//Type of Horse
	cout << "\nEnter type of Horse: (Light, Large, Draft): ";
	cout << (typeHorse);

		//Types
	if (typeHorse == ("Light")) {
		cout << "Light Riding Horse";
	}
		//Type 2
	else if (typeHorse == ("Large")) {
		cout << "Large Riding Horse";
	}
		//Type3
	else if (typeHorse == ("Draft")) {
		cout << "Draft Horse";
	}

		//Weight

		cout << "\nEnter weight of Horse: ";
		cin >> weightHorse;

		//Light Horse

		if (typeHorse == ("Light")) {
			if (weightHorse < 840 || weightHorse > 1200) {
				cout << "\nWeight Category: Optimum";
				poundsFood = (3.0);
			}
			else if (weightHorse < 840) {
				cout << "\nWeight Category: Underweight";
				poundsFood = (3.3);

			}
			else if (weightHorse > 1200) {
				cout << "\nWeight Category: Overweight";
				poundsFood = (2.5);
			}
		}

		//Large Horse

		if (typeHorse == ("Large")) {
			if (weightHorse < 1110 || weightHorse > 1300) {
				cout << "\nWeight Category: Optimum";
				poundsFood = (3.0);
			}

			else if (weightHorse < 1110) {
				cout << "\nWeight Category: Underweight";
				poundsFood = (3.3);
			}

			else if (weightHorse > 1300) {
				cout << "\nWeight Category: Overweight";
				poundsFood = (2.5);
			}
		}
		//Draft Horse

		if (typeHorse == ("Draft")) {
			if (weightHorse < 1500 || weightHorse > 2200) {
				cout << "\nWeight Category: Optimum";
				poundsFood = (3.0);
			}

			else if (weightHorse < 1500) {
				cout << "\nWeight Category: Underweight";
				poundsFood = (3.3);
			}

			else if (weightHorse > 2200) {
				cout << "\nWeight Category: Overweight";
				poundsFood = (2.5);
			}
		}
		cout << "\nFeed:" << poundsFood << "\npounds";

		return (0);


}
My compiler gives no errors and just one warning -
[Warning] unused variable 'weight'


Are you sure the error message comes from this code? If so, at which line number?

Works fine for me except the warning for unused variable 'weight'. But I think there are a few issues:

probably line 28 is incorrect, should be
cin >> (typeHorse);

line 51, 69 and 87 have similar problems. For example, line 51 should be
if (weightHorse >= 840 && weightHorse <= 1200)
Now it would check if the variable is in the range 840 and 1200 (including both).
Topic archived. No new replies allowed.