How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask LogicPro Your Own Question
LogicPro
LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 13165
Experience:  Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
29751445
Type Your Programming Question Here...
LogicPro is online now

C++ I have this working properly by breaking up the if condition

Resolved Question:

C++
I have this working properly by breaking up the if condition into 2 seperate if conditions (nested if), but why isn't it working this way? the Draft category is the only category giving correct results:
#include
#include
using namespace std;
int main() {
int weight;
char choice;
string type, category, food;
while(true) {
cout << "Nancy's Horse Stables" << endl;
cout << left;
cout << setw(15) << "Horse Type" << setw(30) << "Minimum optimum weight"
<< setw(30) << "Maximum optimum weight" << endl;
cout << right << setw(30) << "range in pounds" << setw(30) << "range in pounds" << endl;
cout << "Light" << setw(13) << "840" << setw(31) << "1200" << endl;
cout << "Large" << setw(14) << "1100" << setw(30) << "1300" << endl;
cout << "Draft" << setw(14) << "1500" << setw(30) << "2200" << endl;
cout << "-------------------------------------------------------------------" << endl;
cout <> type;
cout <> weight;
cout << "Horse type: " << type << endl;
cout << "Horse weight: " << weight << endl;
if(type == "Light" && weight 1200)
category = "Overweight";
else
category = "Optimal";
if(type == "Large" && weight 1300)
category = "Overweight";
else
category = "Optimal";
if(type == "Draft" && weight 2200)
category = "Overweight";
else
category = "Optimal";
if(category == "Underweight")
food = "3.3";
else if(category == "Optimal")
food = "3.0";
else
food = "2.5";
cout << "Weight category: " << category << endl;
cout << "Feed amount: " << food << " pounds" << endl << endl;
cout <> choice;
if(choice == 'n')
break;
cout << endl;
}
return 0;
}
Submitted: 2 years ago.
Category: Programming
Expert:  LogicPro replied 2 years ago.
Hi
Welcome
My name is ***** ***** I will help you

Zip all files; upload the zipped file to http://wikisend.com or http://ge.tt and post download link here.

The format is not easy to read.


Also let me know which if condition you are talking about.
Customer: replied 2 years ago.

3 types of horse: Light; Large; Draft

Based on the type of the horse, the program returns if the horse is: underweight; optimal; overweight. the error is related to the if/if else/else statements. the only type of horse that returns the correct weight category is Draft. e.g.: enter 'Light' for type of horse then enter '800' for weight in pounds. the program should return a weight category of 'underweight' but it returns 'optimal' instead (underweight < 840).

Customer: replied 2 years ago.

http://ge.tt/9pTFU322/v/0?c

Expert:  LogicPro replied 2 years ago.
Gary,
Here is the correct code:
http://pastebin.com/raw.php?i=hsD1zihZ

program was not testing the horse type in of conditions except first one.

You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers. It will ensure that question is for me.

Please bookmark my profile page:

http://www.justanswer.com/homework/expert-logicpro/

so you can come back and ask me a question anytime.

Remember, if for any reason you are unsatisfied with my answer, we can continue the conversation until you’re satisfied and rate my answer as excellent. I can address follow up questions on original requirements at no extra charge and I’m always here to help.

Thank you for using this site!

LogicPro and other Programming Specialists are ready to help you
Expert:  LogicPro replied 2 years ago.
Hi again,
Just following up with you to see how everything is going and if you have more questions for me.
You can ask me again using "For LogicPro only" at the start of your questions like you do to get instant answers.
It will ensure that question is for me.
Please bookmark my profile page:
http://www.justanswer.com/homework/expert-logicpro/
so you can come back and ask me a question anytime.
If you need any additional information on this answer, please don't hesitate to ask by clicking on 'Reply to Expert', and I will reply as soon as possible.
I hope you found the information in my answer helpful, and if so, please let me know, here. Thank you!
Thanks very much for using Just Answer!
Best wishes
LogicPro
Expert:  LogicPro replied 2 years ago.
Hi again,
Just following up with you to see how everything is going and if you have more questions for me.
You can ask me again using "For LogicPro only" at the start of your questions like you do to get instant answers.
It will ensure that question is for me.
Please bookmark my profile page:
http://www.justanswer.com/homework/expert-logicpro/
so you can come back and ask me a question anytime.
If you need any additional information on this answer, please don't hesitate to ask by clicking on 'Reply to Expert', and I will reply as soon as possible.
I hope you found the information in my answer helpful, and if so, please let me know, here. Thank you!
Thanks very much for using Just Answer!
Best wishes
LogicPro