|
-
January 10th, 2003, 08:47 PM
#1
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
-
January 10th, 2003, 10:26 PM
#2
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
-
January 10th, 2003, 10:35 PM
#3
thanks
Thanks a bunch! It was so easy that I overlooked it thinking it would be something more complicated than that. Thanks again
-
January 10th, 2003, 11:31 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|