Given the code segment below what will be the output if the integer variable \"
ID: 3545225 • 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
print BMW
if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 ||guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2)//true
print Mercedes
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.