mercredi 31 janvier 2018

How do I combine strings in an if/else statements in C++?

I'm a beginner learning C++, and I'm confused about where I've gone wrong here. So far I have what is below, but it's not recognizing the && operand for this. What would I use in place of &&?

What I'm suppose to be doing is writing a program that prompts the user to enter the names of two primary colors to mix. I'd appreciate any and all advice.

Thank you.

 #include <iostream>
    #include <string>
    #include <iomanip>

    using namespace std;

    int main()
    {
        //Declare string variables for colors to mix

        string color;
        string color2;
        string red;
        string yellow;
        string blue; 

        //Output instructions for creating secondary color
        cout<< " Enter first primary color to help create a secondary color.";
        cout<< " Must be in lowercase letters. "<<endl;

        cin>>color;

        cout<< "Enter another primary color to help create a secondary color: ";
        cout<< " Must be in lowercase letters. "<<endl;
        cin>>color2;


        //Create statements to help determine the results
        if (red && yellow)
        {cout<< " Your secondary color is Orange! ";

        }

        else if (red && blue) 
        {cout<< " Your secondary color is Purple! ";


        }

        else if (blue && yellow) 
        {cout<< " Your secondary color is Green! ";

        }

        else 
        {cout<< "Input is inaccurate. Please enter a different color. ";


        }


        return 0;
    }

Aucun commentaire:

Enregistrer un commentaire