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

Given the code segment below what will be the output if the integer variable \"

ID: 3545224 • Letter: G

Question

Given the code segment below what will be the output if the integer variable "lottery" = 12 and "guess" = 21?


int lotteryDigit1 = lottery/10;

int lotteryDigit2 = lottery%10;


int guessDigit1 = guess/10;

int guessDigit2 = guess%10;


if (guess == lottery)

cout << "Audi" << endl;

if (guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit 1)

cout << "BMW" << endl;

if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 ||

    guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2)

cout << "Mercedes" << endl;

else

cout << "Porsche" << endl;

Explanation / Answer

output:

BMW

Mercedes



Explanation:


lottery=12

guess=21

lotteryDigit1=12/10=1


lotteryDigit2=12%10=2


guessDigit1=21/10=2



guessDigit2=21%10=1


if(guess=lottery) //false

if (guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit 1)//true

output=BMW

if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 ||guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2)//true

output=Mercedes

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