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.
#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;
}
Comments
Leave a comment