CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Posts
    30

    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

  2. #2
    Join Date
    Dec 2002
    Posts
    1,050
    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

  3. #3
    Join Date
    Oct 2002
    Posts
    30

    thanks

    Thanks a bunch! It was so easy that I overlooked it thinking it would be something more complicated than that. Thanks again

  4. #4
    Join Date
    Dec 2002
    Posts
    287
    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
  •  





Click Here to Expand Forum to Full Width

Featured