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

HAS TO BE WRITTEN IN C++ AND PLEASE DO NOT COPY AND PASTE PREVIOUS ANSWER FROM C

ID: 3711322 • Letter: H

Question

HAS TO BE WRITTEN IN C++ AND PLEASE DO NOT COPY AND PASTE PREVIOUS ANSWER FROM CHEGG BECAUSE IT IS WRONG. THANKS IN ADVANCE

Use at least one user defined class in your program. Write a program to have the computer genera try to guess the number. Every time a guess is made, the computer responds with the number of red, yellow, and green digits in the guess. A guess digit is green if the guess digit and the corresponding digit are the same. A guess digit is red if it does not correspond to any of the digits. A yellow guess is if it is a correct digit but not in the correct place Suppose the computer's number is 123. Your output may look as follows Please enter a guess? 422 You have: 2 red 1 green 0 yellow Enter the next guess? 459 You have: 3 red 0 green Oyellow Enter the next guess? 122 You have: 1 red 2 green 0 yellow Enter the next guess? 123 VERIFIED BY: DATE:

Explanation / Answer

#include <iostream>

using namespace std;

void Guess(int x,int y)

{ int a,b;

int r=0, g=0,ye=0;

int c[3] ,i=0;

int og=x;

while(y!=0)

{

a=y%10;

b=x%10;

c[i]=a;

i++;

x/=10;

y/=10;

if((a^b)==0)

g++;

else

r++;

  

}

  

int aa=c[0]*100+c[2]*10+c[1];

if (og==aa)

ye++;

aa=c[1]*100+c[0]*10+c[2];

if (og==aa)

ye++;

  

cout<<"Red is "<<r<<endl;

cout<<"Green is "<<g<<endl;

cout<<"Yellow is "<<ye<<endl;

  

}

int main() {

int xx=rand()%1000+100;

int yy;

cout<<"Computer Number later eliminate this please "<<xx<<endl;

while(xx!=yy){

std::cout <<"Enter a Number" << std::endl;

cin>>yy;

if(xx==yy)

break;

Guess(xx,yy);

}

std::cout <<"Congratulations your guess is corrct" << std::endl;

return 0;

}

Output: