Answer to Question #295406 in C++ for Robot

Question #295406

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:

  • Prompt user to enter a number between 1 and 7
  • Use selection structure such as if-else or switch to find the color based on the previous table
  • Output the color related to input number. See the sample output.
  • Save the output in a file named “color.txt”.
1
Expert's answer
2022-02-08T19:56:24-0500
#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;
}

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