Can't figure out how to perform this task with else/if

So the task is to use if/else statements to write a program that helps the user troubleshoot wifi. It displays a statement like "Try rebooting the router and connecting. Did that fix the problem? Type Y or N." If the user types Y, the program ends, if they type N, it displays another solution to try, and it keeps going like that for a while. I'm not sure how to integrate a cin into each loop that the computer recognizes as a separate loop. So far I have something like,

char input;

cout << "First, reboot the computer and try to connect. Did that work?" << endl;
cout << "Did that fix the problem? Type Y or N." << endl;

cin >> input;

if (input == 'N')
{
cout << "Reboot the computer and try to connect. Did that work?" << endl;
cin >> input;
}
Last edited on
looks like a good start.

Without doing something funky, looping here may be a bit of trouble because each loop has a unique string. you can do something like (pseudoC):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vector<string> questions;
   questions.pushback("First, reboot... etc");
   questions.pushback("Second, something else");
   questions.pushback("Third, .. etc");
   ... for all your question text then

for(j = 0; j < questions.size(); j++)
{
    cout<< questions[j];
    cin >> response;
    if(response=='Y') 
    {
       cout <<"problem solved" << endl; 
       break;
    }
}


you can check explicitly for 'N' or let it ride. I left it off, anything but a Y goes to the next question.

if explicitly told to loop, you have to do something like that to allow iteration over the questions else your loop is pretty obnoxious, looking like:
1
2
3
4
5
6
7
8
for( j = 0; ..etc)
{
    if(j == 1)
    {question 1 code}
    else if (j == 1)
     {question 2 code }
     ... etc
}


here, all the looping saves you is the read and check on the response variable.
Last edited on
Topic archived. No new replies allowed.