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);
|