I’m working on a C++ program that determines the winner of a type of game by com
ID: 3754955 • Letter: I
Question
I’m working on a C++ program that determines the winner of a type of game by comparing the two teams total scores. There are a few combindations of scores that are invalid. At the top of my code I declare a Boolean called “isInvalid” and set it to false. For each invalid score combindation I have an if statement that makes sure to print “invalid result” if that combindation is entered in and I follow that if statement with setting “isInvalid” = True (one of these if statements is the first picture below), now if all entered scores ARE valid then I want it to print who the winner is by first checking if the game is valid (isInvalid = false) and then checking who has the higher score using if statements ( this part is in the 2nd picture). Can you tell me if I have everything formated correctly? If i type in a valid score, it doesn’t print the winner so I think something is wrong with the last part... thanks!!I’m working on a C++ program that determines the winner of a type of game by comparing the two teams total scores. There are a few combindations of scores that are invalid. At the top of my code I declare a Boolean called “isInvalid” and set it to false. For each invalid score combindation I have an if statement that makes sure to print “invalid result” if that combindation is entered in and I follow that if statement with setting “isInvalid” = True (one of these if statements is the first picture below), now if all entered scores ARE valid then I want it to print who the winner is by first checking if the game is valid (isInvalid = false) and then checking who has the higher score using if statements ( this part is in the 2nd picture). Can you tell me if I have everything formated correctly? If i type in a valid score, it doesn’t print the winner so I think something is wrong with the last part... thanks!!
For each invalid score combindation I have an if statement that makes sure to print “invalid result” if that combindation is entered in and I follow that if statement with setting “isInvalid” = True (one of these if statements is the first picture below), now if all entered scores ARE valid then I want it to print who the winner is by first checking if the game is valid (isInvalid = false) and then checking who has the higher score using if statements ( this part is in the 2nd picture). Can you tell me if I have everything formated correctly? If i type in a valid score, it doesn’t print the winner so I think something is wrong with the last part... thanks!!
if (tl s1&& t2 s 1) cout
Explanation / Answer
you made wrong in last two function,
You wrote IsInvalid=false, which means assignemnt, means you are assigning false to vaiable Isinvalue, but actuall you wanted to compare them so that should be: IsInvalid==false.
so correcte code:
if(isInvalid==false && t1_total>t2_total)
{
cout<<"Team 1 won the game";
}
if(isInvalid==false && t2_total>t1_total)
{
cout<<"Team 2 won the game";
}
please give thumbs up, thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.