Hi guys,

I'm not sure if this can be done or not, but I'm writing code for a C++ course at uni and my main starts as follows:

cout << "Do you want to start a list of shapes? [Y]es or [N]o?" << endl;
	cin >> c;
	switch(c){
		case 'Y':
		case 'y':
			j = 1;
		break;

		case 'N':
		case 'n':
			j = 0;
		break;

		default:
			cout << "\nYou have not entered a valid character. " << endl;

	} //end of switch

The thing is, I want it to loop back and ask again if any key is pressed but Y and N. Is this possible using switches or do I have to use if/else instead?

Cheers,

Jen

put the switch in a while loop like

while(c != 'e')   //or any thing else
{
//switch code...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.