jeudi 21 septembre 2017

C++: goto and user input not working together

I am working on C++, and using a basic authentication method using if statements, so what I have here, is when the the input is not the desired combination, it will say Access denied and ask the user if they want to try again or quit. I tried doing this using the goto variable, but it hasn't been working. Help please? (Full code: http://ift.tt/2fcRhZh)

    else {
    cout << "Access denied..." << " Try again? (Y/N) >" << flush;
    string ask;
    cin >> ask;
    if(ask == "N" || "n"){
      cout << "Shutting down..." << endl;
      goto end;
    }
    else if(ask == "Y" || "y"){
      goto restart;
    }

    else {
      cout << "Invalid option." << endl;
      goto restart;
    }
  }

  end:
  return 0;

Aucun commentaire:

Enregistrer un commentaire