-
Program nested if help
I am trying to nest if statements in my program, but it asks all of the questions even if it doesn't meet the criteria.
For Example:
cout << "Does " << patient_name<<" have a cough? ";
cin >> Q4;
if (Q4 == "yes" || "Yes")
{
cout << "Does "<< patient_name<<" have a dry cough? ";
cin >> Q4_a;
if (Q4_a == "no" || "No")
{
cout << "Does "<< patient_name<<" have a mild hacking cough? ";
cin >> Q4_b;
if (Q4_b == "no" || "No")
{
cout << "Does "<< patient_name<<" have a severe cough? ";
cin >> Q4_c;
}
}
}
Why is it asking if the user has a mild hacking cough and a severe cough if the user inputs that he already has a dry cough? I want it to prompt the user if the patient has a dry cough, and if he does I don't want it to ask if he also has a mild hacking and a severe cough.
THANKS :)
-
Hi gurlygurlz
I suspect Q4 and the other input variables are string ? or are
they char* ?
anyway the lines like
if (Q4 == "yes" || "Yes")
should be this if they are string or
if ((Q4 == "yes") || (Q4 == "Yes"))
If they are char* then use strcmp() instead of ==
mdmd
-
thanks
Thanks a bunch! It was so easy that I overlooked it thinking it would be something more complicated than that. Thanks again :)
-
Don't want to be rude but you had very similar problems a while ago :)
if (symptom_number == 1&&2&&4&&5)
http://www.codeguru.com/forum/showth...ght=gurlygurlz
Dan