C++ Program to Demonstrate use of Do While Loop

Write C++ Program to Demonstrate use of Do While Loop

// CPP Program to Demonstrate use of Do While Loop

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{

    int n;

	do
	{
		cout << "\n\n1. Hello World";
		cout << "\n2. Welcome to the world of programming";
		cout << "\n3. Exit";
		cout << "\n\nEnter Your Choice :--> ";
		cin >> n;

		int temp = n;
		switch(temp)
		{
			case 1:
				cout << "\nHello World";
                break;

			case 2:
				cout << "\nWelcome to the world of programming";
                break;

			case 3:
				exit(0);

			default:
				cout << "\nPlease enter the valid number";
		}
	}while(n>0);

	return 0;
}

Output:

1. Hello World
2. Welcome to the world of programming
3. Exit

Enter Your Choice :--> 5

Please enter the valid number

1. Hello World
2. Welcome to the world of programming
3. Exit

Enter Your Choice :--> 2

Welcome to the world of programming

1. Hello World
2. Welcome to the world of programming
3. Exit

Enter Your Choice :--> 3

≪ Previous | Next ≫