In: Computer Science
Language C++
Ask the user to enter the name of one primary color (red, blue, yellow) and a second primary color that is different from the first. Based on the user's entries, figure out what new color will be made when mixing those two colors. Use the following guide:
If the user enters anything that is outside one of the above combinations, return an error message.
Prompts:
Enter a primary color (red, blue, yellow): [possible user input: red]
Enter a different primary color (red, blue, yellow): [possible user input: blue]
Possible Outputs:
red and blue make purple
blue and yellow make green
yellow and red make orange
You entered invalid colors
Notes and Hints:
1) The program should work regardless of the color order. In other words, it shouldn't matter if the user enters red or blue first...the two colors make purple.
2) Regarding #1, this means that the first three outputs shown above may appear with the colors in a different order. Hint: Use variables in your output to make this easy!
3) If the user has any uppercase letters, it will not work. This is normal, as C++ is case sensitive. We will solve this problem in a future in-class lesson.
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int main() {
string primary,secondary;
cout << "Enter Primary Color: ";
cin>>primary;
cout << "Enter Secondary Color: ";
cin>>secondary;
if((primary == "red" && secondary == "blue") || (primary == "blue" && secondary == "red")) cout<<primary<<" and "<<secondary<<" makes purple"<<endl;
else if((primary == "yellow" && secondary == "blue") || (primary == "blue" && secondary == "yellow")) cout<<primary<<" and "<<secondary<<" makes green"<<endl;
else if((primary == "red" && secondary == "yellow") || (primary == "yellow" && secondary == "red")) cout<<primary<<" and "<<secondary<<" makes orange"<<endl;
else cout<<" You entered Invalid Colours";
}