while loop example


 

//while_ex.cpp
// while loop example


#include <iostream> 
using namespace std;

int main()
{
					//variable declarations
	char again;		//for asking user to continue
	int num;		//for user input of a number

	again = 'y';	//initialize again variable to y

	//begin while loop
	while (again == 'y')	//test for again = y
	{
		cout << "\nEnter a whole number: \n";		//get number from user
		cin  >> num;

		cout << "\tYou entered " << num << endl;	//output number
		cout << "\n\t\tWould you like to input another number? (y/n)"; //continue?
		cin  >> again;

	} //end of while loop

	cout << "\n*-*-*-*-*-*-OK, we're done with this activity!*-*-*-*-*\n\n" ;

	return 0;
} //end of main