Q6 Write a program for a matchstick game being played between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows: – There are 21 matchsticks. – The computer asks the player to pick 1, 2, 3, or 4 matchsticks. – After the person picks, the customer does its picking. – Whoever is forced to pick up the last matchstick loses the game.
Program: 99
Write a c program for a matchstick game being played between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows:
- There are 21 matchsticks.
- The computer asks the player to pick 1, 2, 3, or 4 matchsticks.
- After the person picks, the customer does its picking.
- Whoever is forced to pick up the last matchstick loses the game.
Output:
Total Match Sticks: 21 Pick up the match sticks between (1 to 4): 1 Computer picks up the 4 match sticks. Total Match Sticks: 16 Pick up the match sticks between (1 to 4): 2 Computer picks up the 3 match sticks. Total Match Sticks: 11 Pick up the match sticks between (1 to 4): 3 Computer picks up the 2 match sticks. Total Match Sticks: 6 Pick up the match sticks between (1 to 4): 4 Computer picks up the 1 match sticks. You have been lost via computer.
if(user_choice>4)
{
printf(“Invalid Entry”);
break;
}
don’t you think this is wrong.
sorry may mistake i got it.
can you explain. how it’s wrong?
if(user_choice > 4 && user_choice < 1);
{
Printf(“Invalid Entry”);
break;
}
This is the right code.
It will work definitely.