Stuck on the if statements

Description:
In this assignment, you will develop a C++ program to determine if a horse is overweight or underweight, given the type of horse. Once the determination has been made, calculate how much you should feed the horse given their weight.
Use the table below to write a program which prompts the user to enter the type of horse and its weight. The program will display whether the horse is underweight, optimal weight, or overweight and how much to feed the horse.
Type of Horse Minimum optimum weight range in pounds Maximum of optimum weight range in pounds
Light riding horse 840 1200
Large riding horse 1,100 1,300
Draft horse 1,500 2,200

How many pounds of food to feed the horse given their weight status:
Underweight Optimum Overweight
3.3 3.0 2.5

Requirements:
1. Use variable names that are descriptive and initialized.
2. Use an if-else statement for the determination of weight status given the type of horse and how much to feed the horse.
3. Verify that the user has entered the type of horse correctly.
4. The output must be labelled and easy to read as shown in the sample outputs included in this document.

The outputs, and switch works fine. My problem is with the if else statements.
whats happening is say I choose choice 3.Draft horse and enter the horse's weight as 1400 instead of it saying underweight the program tells me that the weight is overweight; which is true if I had chosen choice 2. I know the error i within the if statements but I'm unsure of how to fix it. please help.


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
  #include <iostream>

using namespace std;
 int main()
{
	int choice;
	double type;
	cout << "\nTess's Horse Stable";
	cout << "\n_________________________________________________________________________";
	cout << "\nHorse Type               Minimum Optium Weight       Maximum Optimum Weight" << endl;
	cout << "______________________________________________________________________________";
	cout << "\n1. Light Riding Horse       840                         1200" << endl;
	cout << "\n2. Large Riding Horse       1100                        1300" << endl;
	cout << "\n3. Draft Horse              1500                        2200" << endl;
	cout << "\nEnter type of horse <1-3> : ";
	cin >> choice;

	switch (choice)
	{
	case 1:
		
		cout << "\nLight Riding Horse" << endl;
		break;
	case 2:
		
		cout << "\nLarge Riding Horse" << endl;
		break;
	case 3:
		
		cout << "\nDraft Horse" << endl;
		
		break;
	default:
		cout << "\nInput error...program will close!!!" <<endl;
		system("pause");
		return(0);
	}



	cout << "\nEnter horse's weight in pounds: ";
	cin >> type;
	cout << "\nThe horse weighs " << type << " pounds";


	if (type < 840){
		cout << "\nWeight Category: Underweight";
		cout << "\nFeed Category: 3.3 pounds";
	}

	else if (type >= 840 && type < 1200){
		cout << "\nWeight Category: Optium";
		cout << "\nFeed: 3.0 pounds";}

	else if (type> 1200){
		cout << "\nWeight Category: Overweight";
		cout << "\nFeed: 2.5 pounds";}

	else if (type < 1100){
		cout << "\nWeight Category: Underweight";
		cout << "\nFeed Category: 3.3 pounds";}

	else if (type >= 1100 && type <1300){
		cout << "\nWeight Category: Optium";
		cout << "\nFeed Category: 3.0 pounds";}

	else if (type> 1300){
		cout << "\nWeight Category: Overweight";
		cout << "\nFeed: 2.5 pounds";}

	else if (type < 1500){
		cout << "\nWeight Category: Underweight";
		cout << "\nFeed Category: 3.3 pounds";}

	else if (type >= 1500 && type < 2200){
		cout << "\nWeight Category: Optium";
		cout << "\nFeed Category: 3.0 pounds";}

	else if (type > 2200){
		cout << "\nWeight Category: Overweight";
		cout << "\nFeed: 2.5 pounds";}




	cout << endl << endl;
	system("pause");
	return (0);
IMO if you were to follow the requirements more closely you would probably see part of the problem. For example:
1. Use variable names that are descriptive and initialized.

To me you fail on this point for both items. The variables are not descriptive and are not initialized.

You have a variable named choice that you use to store the type of the horse.

You have a variable named type that you use to store the weight information.

Wouldn't meaningful variable names mean something like type for the type of horse and maybe weight for the weight of the horse.

2. Use an if-else statement for the determination of weight status given the type of horse and how much to feed the horse.

No where in you assignment description is a switch statement mentioned.

Now in your if() statements, where are you relating the type of horse to the weight of the horse?

In line 51 you write this
1
2
3
4
5
6
7
[
else if (type >= 840 && type < 1200){
/code]

But in line  59,you state 1100,which comes between 840 and 1200.
[code]
else if (type < 1100){


Likewise you can join if-elses in lines 67 and 71 together like this
1
2
3
4
else if( (type>=1300) && (type<1500))
{
//do something.....
}


Your source of error might be there, i think you dont know how to express your issue.
Try this(its a humble patch-up) and tell if it works. :)
@jlb I apologize I should have clarified, this weeks lecture and all the in class assignments have been about switch statements. It would be a little unusual for the take home assignment to not have a switch statement. Thanks for the feedback on making the variables easier to read I'll work on that. @MaBunny I'm sorry the if statements look confusing I'll take care of that. What I'm aiming for is for each selection to have it's own if-else statement. I'm not sure if that's possible since I'm new to all of this and C++ is overwhelming for me. Thank you both for the feedback and quick responses.

Topic archived. No new replies allowed.