You work in a printing office that the machine there can print documents in different colors. It gets an integer number between 1 to 7 and prints the documents in rainbow colors, as shown in the following table:
Number Matched Color
1 ------- red
2 ------- orange
3 ------- yellow
4 ------- green
5 ------- blue
6 ------- indigo
7 ------- violet
Design an algorithm and write a C++ program to do the following:
#include <iostream>
#include <fstream>
int main()
{
int color = 0;
std::cout << "Enter value : ";
std::cin >> color;
system("cls");
std::string color_name = "";
if (color == 1)
{
color_name = "red";
system("color 4");
}
else if (color == 2)
{
color_name = "orange";
system("color C");
}
else if (color == 3)
{
color_name = "yellow";
system("color 6");
}
else if (color == 4)
{
color_name = "green";
system("color 2");
}
else if (color == 5)
{
color_name = "blue";
system("color 1");
}
else if (color == 6)
{
color_name = "indigo";
system("color 5");
}
else if (color == 7)
{
color_name = "violet";
system("color D");
}
std::cout << "Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
std::ofstream file;
file.open("color.txt");
file << color_name;
file.close();
system("pause");
return 0;
}
Comments
Leave a comment