Answer to Question #297958 in C++ for aniket

Question #297958

write a menu-driven program that asks the user to select a favorite color from the given colors. Keep asking the user three times for selecting the color from the list of the available colors. Do this with the help of a suitable loop and switch statement. Finally, you have to display the three favorite colors of the user. 


1
Expert's answer
2022-02-15T09:32:06-0500


#include <iostream>
#include <string>


using namespace std;


int main()
{
	int ch;
	string selectedColors[3];
	int count=0;
	do{
		cout<<"1. Red\n";
		cout<<"2. Yellow\n";
		cout<<"3. White\n";
		cout<<"4. Green\n";
		cout<<"5. Blue\n";
		cout<<"6. Black\n";
		cout<<"7. Orange\n";
		cout<<"Select color: ";
		cin>>ch;


		switch(ch){
		case 1:
			selectedColors[count]="Red";
			count++;
			break;
		case 2:
			selectedColors[count]="Yellow";
			count++;
			break;
		case 3:
			selectedColors[count]="White";
			count++;
			break;
		case 4:
			selectedColors[count]="Green";
			count++;
			break;
		case 5:
			selectedColors[count]="Blue";
			count++;
			break;
		case 6:
			selectedColors[count]="Black";
			count++;
			break;
		case 7:
			selectedColors[count]="Orange";
			count++;
			break;
		}


	}while(count<3);
	cout<<"\nSelected colors:\n";
	for(int i=0;i<count;i++){
		cout<<selectedColors[i]<<"\n";
	}
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment