Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the image below, the C++ function getColors is supposed to get two colors fro

ID: 3857849 • Letter: I

Question

In the image below, the C++ function getColors is supposed to get two colors from the user. If the user enters something other than a primary color ( RED = 1, BLUE = 2, YELLOW = 3) OR if the user enters two of the same colors, a message should be displayed: "Invalid colors." Otherwise the message should be "Those are valid colors." The function getColors should be of type bool. My if statements are not correct because even if I enter two of the same numbers, the message, "Those are valid colors." is displayed. Please help me fix my if statements.

es rsymbols Resouroes 13 bool get Colors (int &, int & 14 int determine Color (1 15 void print color 15 17 int main o 18 int co11, co12: 19 if (getColors (coll co12 cout Tho arc valid colors." endl. 21 22 el 23 cout Invalid colors endl; return, 0 25 26 27 bool get colors (int & coll, int & co12) 28 H cout Enter your two primary colors i for red, 2 for blue, and 3 for yellow endl. 29 cout The two colors must be different." endl; 30 31 cin coll, co12 32 bool status 33 if C::11. status false; 31 35 else 36 if col1 RED && col1 BLUE coll YELLOM 37 status false 38 if co12 RED & & co12 BLUE & & col2 YELLOW 39 falae status 41 status true return status; 44 & oth ld GNU GCC Comp11 Debug SSt... varning: richt operand of cama operator has ao erect Runused traiuej

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;
#define RED 1
#define BLUE 2
#define YELLOW 3

bool getColors(int&,int&);


int main(int argc, char const *argv[])
{
   int col1,col2;
   if(getColors(col1,col2))
   {
       cout<<"Those are valid colors "<<endl;
   }
   else
   {
               cout<<" Invalid colors "<<endl;

   }
   return 0;
}

bool getColors(int& col1,int& col2)
{
   cout<<"Enter your two primary colors: 1 for red,2 for Blue and 3 for yellow ";
   cout<<"Two colors must be different ";
   cin>>col1>>col2;
   bool status=true;
   if(col1==col2)
       status=false;
   else
   {
       if(col1!=BLUE&&col1!=RED&&col1!=YELLOW&&col2!=BLUE&&col2!=RED&&col2!=YELLOW)
           status=false;
       else
           status=true;
  

   }
   return status;
}

===========================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter your two primary colors: 1 for red,2 for Blue and 3 for yellow
Two colors must be different
2 2
Invalid colors

======================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote