C++ Program or Beginners The colors red, blue, yellow are known as the primary c
ID: 3671992 • Letter: C
Question
C++ Program or Beginners
The colors red, blue, yellow are known as the primary colors because they cannot be made by mixing other colors. When you mmix two primary colors, you get a secondary color, as shown here:
When you mix red and blue, you get purple.
When you mix red and yellow, you get orange.
When you mix blue and yellow, you get green.
Write a program that prompts the user to enter the names of two primary colors to mix. If the user enters anything other than “red”, “blue”, or “yellow”, the program should display an error message. Otherwise, the program should display the name of the secondary color that results by mixing two primary colors.
Explanation / Answer
#include<string>
#include <iostream>
using namespace std;
int main()
{
string color1, color2;
cin >> color1 >> color2;
if ( (color1 == "red" && color2 == "blue") || (color2 == "red" && color1 == "blue") )
cout << "purple";
else if ( (color1 == "red" && color2 == "yellow") || (color2 == "red" && color1 == "yellow") )
cout << "orange";
else if ( (color1 == "blue" && color2 == "yellow") || (color2 == "blue" && color1 == "yellow") )
cout << "green";
else {
cout<<"error message";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.