fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void STUFF()
  5. {
  6. cout << "Doing stuff..." << endl;
  7. }
  8.  
  9. int CREDS;
  10. void AUTH()
  11. {
  12. cout << "Username: "; string USER; cin >> USER;
  13. cout << "Password: "; string PASS; cin >> PASS;
  14. if (USER == "josh" and PASS == "passwd")
  15. {
  16. CREDS = 0;
  17. }
  18. else
  19. {
  20. CREDS = 1;
  21. };
  22. }
  23.  
  24. void RETRY()
  25. {
  26. cout << "Authentication failed! Try again? [Y/n]" << endl; char REPLY; cin >> REPLY;
  27. if (REPLY == 'Y' or REPLY == 'y')
  28. {
  29. AUTH();
  30. }
  31. else if (REPLY == 'N' or REPLY == 'n')
  32. {
  33. cout << "Exiting..." << endl;
  34. }
  35. else
  36. {
  37. RETRY();
  38. };
  39. }
  40.  
  41. int main()
  42. {
  43. AUTH();
  44. if (CREDS == 0)
  45. {
  46. STUFF();
  47. return 0;
  48. }
  49. else if (CREDS == 1)
  50. {
  51. RETRY();
  52. };
  53.  
  54. }
Success #stdin #stdout 0s 15240KB
stdin
josh
passwd
stdout
Username: Password: Doing stuff...