Skip to content

Instantly share code, notes, and snippets.

@sprintr
Last active December 11, 2015 18:38
Show Gist options
  • Save sprintr/4642754 to your computer and use it in GitHub Desktop.
Save sprintr/4642754 to your computer and use it in GitHub Desktop.
An example of do while
#include <cstdlib>
#include <iostream>
using namespace std;
// standard c++
int main(int argc, char *argv[])
{
// even if (choice = 'N'), do will run once
char choice = 'Y';
do {
int a = 0,
b = 0,
c = 0;
cout << "Enter a and b" << endl;
cin >> a >> b;
c = a + b;
cout << "a + b = " << c << endl;
cout << "Do you want to continue (Y/N)?" << endl;
cin >> choice;
} while(choice == 'Y');
system("PAUSE");
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment