etonw

do-while loop for deciding to repeat a section of code

May 31st, 2022 (edited)
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. // do-while loop for deciding to repeat a section of code
  2.     do{
  3.  
  4.     // initialize variables
  5.     char ans;
  6.  
  7.     // prompt
  8.  
  9.     // Echo inputs
  10.    
  11.     // calculation
  12.    
  13.         cout << "\nHello\n\n";
  14.         cout << "Continue Program  (y/n) ? \n";
  15.         cin >> ans;
  16.        
  17.     } while(ans == 'y' || ans == 'Y');
  18.    
  19.     // output
  20.     cout << "\n\t\t\t\t\t\t\tGood-bye\n";
  21.     cout << "\n\n\t\t\t\t\t\t\t~ End of Program ~\n" << endl;
Add Comment
Please, Sign In to add comment