Here is my code thus far, the problem I am now having, is that when I get to the else if function, it will cout only the if function, however if my input = one of the else if variables, the program will not cout my statement, and will exit. However, if I run the code in an online compiler, it runs properly and returns everything properly. Appreciate the help!
PS... I have tried to put in the code brackets but it is not letting me for some reason.
#include <iostream>
#include <iomanip>
using namespace std;
if (type == 1)
{
cout << "Light riding horse\n";
}
else if (type == 2)
{
cout << " Large riding horse\n";
}
else if (type == 3)
{
cout << "Draft riding horse\n";
}
cout << " Input the weight of horse in pounds";
cin >> weight;
cout << " The Horses weight is " << weight << " pounds\n";
// underweight, optimum, and overweight variables.
float uw, o, ow;
uw = 3.3;
o = 3.0;
ow = 2.5;
// output of food in pounds to feed horse.
// lighthorse
if ( type == 1 && weight < 840)
{
cout << " Your horse is underweight, you should feed " << uw << " pounds of food";
}
else if (type ==1 && weight > 840 && weight < 1200)
{
cout << " Your horse is optimum weight, you should feed " << o << " pounds of food.";
}
else if ( type == 1 && weight > 1200)
{
cout << "Your horse is overweight, you should feed " << ow << " pounds of food.";
}
//largehorse
else if (type == 2 && weight < 1100)
{
cout << "Your horse is underweight, and you should feed " << uw < " pounds of food.";
}
else if (type == 2 && weight > 1100 && weight < 1300)
{
cout << "Your horse is optimum weight, you should feed " << o << " pounds of food";
}
else if ( type == 2 && weight > 1300 )
{
cout << "Your horse is overweight, and you should feed " << ow << " pounds of food.";
}
//drafthorse
else if (type == 3 && weight < 1500)
{
cout << "Your horse is underweight, you should feed " << uw << " pounds of food.";
}
else if (type == 3 && weight > 1500 && weight < 2200)
{
cout << "Your horse is optimum weight, and you should feed " << o << " pounds of food";
}
else if ( type == 3 && weight > 2200)
{
cout << " Your horse is overweight, and you should feed " << ow << " pounds of food.";
}
system("PAUSE");
return 0;
}
that code doesn't compile because you've got a typo, ¿how the hell you've got a typo?
> when I get to the else if function, it will cout only the if function,
> however if my input = one of the else if variables, the program will not cout
> my statement, and will exit.
¿may provide an input/output example?
> However, if I run the code in an online compiler, it runs properly and
> returns everything properly
perhaps your eyes are deceiving you.
try running from withing a terminal.
cout << "Your horse is underweight, and you should feed " << uw < " pounds of food.";
This should be:
cout << "Your horse is underweight, and you should feed " << uw << " pounds of food.";
Also you should consider using double instead of float, else your uw, o, ow will be demoted. I tried your program with VS 2015 and works flawlessly, no matter what condition is tested. :)