Answer to Question #293938 in C++ for Varun Dogra

Question #293938

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-04T14:49:51-0500
#include <iostream>
#include <string>


using namespace std;


int main(){


	string selectedColors[3];
	int selectedColorCount=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";
		int ch;
		cout<<"Select color: ";
		cin>>ch;


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


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




	cin>>selectedColorCount;
	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

LATEST TUTORIALS
New on Blog