C++ Programming help? ?

Hey everyone, I have been stuck on this "Wifi tree" problem and I think I have it correct but I still keep getting errors. Thoughts?

#include <iostream>

#include <string>

using namespace std;

int main()

{

    char answer;

    char y;

    char n;

    string ansyes;

    ansyes = "Glad to be of help.";

    cout << "I see you are having trouble with your connection, let me try to help you." << endl;

    cout << "Reboot the computer and try to connect." <<endl;

    cout << "Did that fix the problem? Type y or n using lowercase letters.";

    cin >> answer;

    do

    {

       cout << ansyes << endl;

    }

     while

        (answer==y); && (answer!=n);

    if (answer==n) && (answer!=y)

    {

        cout << "Make sure the cables between the modem and router are plugged in firmly.";

    }

    cout << "Did that fix the problem? Type y or n using lowercase letters.";

    cin >> answer;

    if (answer==n) && (answer!=y)

    {

      cout << "Move the router to a new location.";

    }

      cout << "Did that fix the problem? Type y or n using lowercase letters.";

      cin >> answer;

      if (answer==n) && (answer!=y)

      {

        cout << "Get a new router.";

      }

      return 0;

}

2 Answers

Relevance
  • VP
    Lv 7
    1 month ago

    - Fix all of your IFs... character comparisons look like this: 'n' or 'y' -- use single quotes!

    - You only need to test for 1 condition in your case.

    - That loop is not needed. You need to say, "Glad to be of help" anytime they don't answer with an 'n'.

  • 1 month ago

    This has a couple of typos, to start with:

    do

    {

    cout << ansyes << endl;

    }

    while

    (answer==y); && (answer!=n);

    Should be:

    do

    {

    cout << ansyes << endl;

    }

    while

    (answer != y) && (answer != n);

    The rest of the if() statements have redundant sections - if the answer is "n" then it can never be "y" so the &&(second clause) is pointless.

    • Robert J
      Lv 7
      1 month agoReport

      Sorry, misread that section. It should just have the == y part.

      I often have a do/while loop around a yes/no input section, that loops back if any other character is entered. I took it to be that type of thing because of the double condition.

Still have questions? Get your answers by asking now.