C++ program to display the colours of rainbow as per the user choice.
Answers
#include<iostream.h>
#include<conio.h>
void main()
{
int color_code;
cout<<"Enter the color code : ";
cin>>color_code;
while ((color_code > 1) && (color_code < 8))
{
switch(color_code )
{
case 1:
{
cout<<"Color is Violet";
cout<<endl;
break;
}
case 2:
{
cout<<"Color is Indigo";
cout<<endl;
break;
}
case 3:
{
cout<<"Color is Blue";
cout<<endl;
break;
}
case 4:
{
cout<<"Color is Green";
cout<<endl;
break;
}
case 5:
{
cout<<"Color is Yellow";
cout<<endl;
break;
}
case 6:
{
cout<<"Color is Orange";
cout<<endl;
break;
}
case 7:
{
cout<<"Color is Red";
cout<<endl;
break;
}
default:
{
cout<<" No Color code defined";
break;
}
cin>>color_code;
}
cout<<endl;
cout<<"End of the Program ";
}
Answer:
"#include<iostream.h>
#include<conio.h>
void principle()
{
int code;
clrscr();
cout<<""Enter the shading code : "";
cin>>code;
if(code==1 )
{
cout<<""Color is Red"";
}
else if(code==2)
{
cout<<"" Color is Green"";
}
else if(code==3)
{
cout<<"" Color is White"";
}
else if(code==4)
{
cout<<""Color is Yellow"";
}
else
{
cout<<"" No Color code characterized"";
}
cout<<endl;
cout<<""End of the Program "";
getch();
}"
Explanation: