/* Color Mixer - The colors red, blue, and yellow are known as the primary colors
because they cannot be made by mixing other colors. When you mix two primary
colors, you get a secondary color.
* 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.
This program 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
displays an error message. Otherwise, the program displays the name of the
secondary color that results by mixing two primary colors. */
#include "Utility.h"
int main()
{
/* Hold color names */
string red = "red";
string blue = "blue";
string yellow = "yellow";
/* Hold input for color1 color2 */
string color1 = " ";
string color2 = " ";
/* Hold mixed colors */
string mixedColorPurple = "purple",
mixedColorOrange = "orange",
mixedColorGreen = "green";
/* Ask the user for two colors */
cout << "Enter a base color name: ";
getline(cin, color1);
cout << "Enter a second color: ";
getline(cin, color2);
/* Determine the color mix and display the output */
if (color1 == "red" && color2 == "blue" || color1 == "blue" && color2 == "red")
{
cout << "This gives you " << mixedColorPurple << endl;
}
else if (color1 == "red" && color2 == "yellow" || color1 == "yellow" && color2 == "red")
{
cout << "This gives you " << mixedColorOrange << endl;
}
else if (color1 == "blue" && color2 == "yellow" || color1 == "yellow" && color2 == "blue")
{
cout << "This gives you " << mixedColorGreen << endl;
}
else
{
/* If color1 or color2 does not equal valid color input an error message is displayed */
(!(color1 == "yellow" || color1 == "blue" || color1 == "red" || (!(color2 == "yellow" || color2 == "blue" || color2 == "red")))) ?
cout << "You entered: " << color1 << ". This one is not a valid color choice!\n"
<< "Valid choices are: ""red"", ""blue"", and ""yellow""\n":
cout << "You entered: " << color2 << ". This one is not valid!\n"
<< "Valid choices are: ""red"", ""blue"", and ""yellow""\n";
}
pauseSystem();
return 0;
}
Friday, November 18, 2016
Programming Challenge 4.8 - Color Mixer
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment