Teaching myself C++, but I have come across a problem in my book that I cannot get past.
Here it is:
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, 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.
The problem is that the IF / ELSE statements will not compare a String to an Int. Im not sure if i should even use strings, but i have no clue what to do next.
I have looked online to see if anyone has posted an explanation but the only ones i found for this problem were in python.
This is my first post, please dont hurt me. :D
This is my code so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string color1, color2;
int red, blue, yellow;
red = 1;
blue = 2;
yellow = 3;
cout << "Please choose 2 primary colors (lower case)." << endl;
cout << "Enter color one: ";
getline(cin, color1);
cout << "Enter color two: ";
getline(cin, color2);
if (color1 == red) // i get a red line under all the == operator.
if (color2 == blue)
cout << "Purple" << endl;
else if (color2 == yellow)
cout << "Orange" << endl;
else if (color1 == blue)
if (color2 == red)
cout << "Purple" << endl;
else if (color2 = yellow)
cout << "Green" << endl;
else if (color1 == yellow)
if (color2 = red)
cout << "Orange" << endl;
else if (color2 = blue)
cout << "Green" << endl;
else
cout << "Please choose 2 primary colors (lower case)." << endl;
system("pause");
return 0;
}
|