Not Getting Output Needed
Oct 9, 2014 at 5:34pm UTC
Okay, So I have this program and it's trying to output the type of horse and then how much food it needs. However, the program won't execute when it gets the to if statement checking the weight range. Here is what I have:
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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string horseType;
const double UNDERWEIGHT = 3.3, OPTIMUM = 3.0, OVERWEIGHT = 2.5;
double weight, feed;
cout<< "Enter the horse type ('Light Horse', 'Large Horse', or 'Draft Horse'): " ;
getline(cin, horseType);
cout<< "Enter the horse weight in whole pounds" <<endl;
cin >> weight;
cout<<setprecision(2)<<fixed;
cout<< "Horse Weight: " << weight <<endl;
if (horseType == "Light Horse" || horseType == "light horse" )
if (weight >= 840 && weight <= 1200)
{
cout<<"Weight Category: Optimum" <<endl;
feed = (weight / 1000) * OPTIMUM;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight < 840)
{
cout<<"Weight Category: Underweight" <<endl;
feed = (weight / 1000) * UNDERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight > 1200)
{
cout<<"Weight Category: Overweight" <<endl;
feed = (weight / 1000) * OVERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (horseType == "Large Horse" || horseType == "large horse" )
if (weight >= 1100 && weight <= 1300)
{
cout<<"Weight Category: Optimum" <<endl;
feed = (weight / 1000) * OPTIMUM;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight < 1100)
{
cout<<"Weight Category: Underweight" <<endl;
feed = (weight / 1000) * UNDERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight > 1300)
{
cout<<"Weight Category: Overweight" <<endl;
feed = (weight / 1000) * OVERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (horseType == "Draft Horse" || horseType == "draft horse" )
if (weight >= 1500 && weight <= 2200)
{
cout<<"Weight Category: Optimum" <<endl;
feed = (weight / 1000) * OPTIMUM;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight < 1500)
{
cout<<"Weight Category: Underweight" <<endl;
feed = (weight / 1000) * UNDERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight > 2200)
{
cout<< "Weight Category: Overweight" <<endl;
feed = (weight / 1000) * OVERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
return 0;
}
Oct 9, 2014 at 7:45pm UTC
Add temporary code to print the horse type before line 24. Maybe the value isn't what you expect it to be.
Oct 9, 2014 at 7:48pm UTC
Nevermind. The problem is that the compiler doesn't interpret the code the way your indenting suggests. It's actually like this:
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
if (horseType == "Light Horse" || horseType == "light horse" )
if (weight >= 840 && weight <= 1200)
{
cout<<"Weight Category: Optimum" <<endl;
feed = (weight / 1000) * OPTIMUM;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight < 840)
{
cout<<"Weight Category: Underweight" <<endl;
feed = (weight / 1000) * UNDERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight > 1200)
{
cout<<"Weight Category: Overweight" <<endl;
feed = (weight / 1000) * OVERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (horseType == "Large Horse" || horseType == "large horse" )
if (weight >= 1100 && weight <= 1300)
{
cout<<"Weight Category: Optimum" <<endl;
feed = (weight / 1000) * OPTIMUM;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight < 1100)
{
cout<<"Weight Category: Underweight" <<endl;
feed = (weight / 1000) * UNDERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (weight > 1300)
{
cout<<"Weight Category: Overweight" <<endl;
feed = (weight / 1000) * OVERWEIGHT;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
else if (horseType == "Draft Horse" || horseType == "draft horse" )
if (weight >= 1500 && weight <= 2200)
{
cout<<"Weight Category: Optimum" <<endl;
feed = (weight / 1000) * OPTIMUM;
cout<<"Feed Amount " <<feed<<" pounds" <<endl;
}
Topic archived. No new replies allowed.