1
I need to make a program that is a game, where the user will input a number and I must determine if it is possible for the user to win the game through a printf saying "Yes" or "No", it is not necessary to show the steps of the program. The game is based on the following rule:
*If the number is even half the number is removed;
*If the number is multiplied by 3 or 4, multiply the last 2 digits of the number and subtract from its total;
*If the number is multiples of 5 subtracts 42 from it;
The goal of the game is to finish with the number 42 if you don’t lose. Follow an example below:
1-You start with 250.
2-Like 250 is divisible by 5, you can take out 42, leaving as rest 208.
3-As 208 is even, you can take out half of the total, leaving 104 as rest.
4-As 104 is even, you can take half of the total, leaving 52 as rest.
5-Since 52 is divisible by 4, you can multiply the last two digites of 52 (resulting in 10) and delete 10. This leaves you with 42 left.
Ready! The goal has been achieved! Note, however, that in both step 2 and step 5, you could have used the n even rule. In both cases, you would lose.
for the time being I have the following code:
#include<stdio.h>
int teste1(int num);
int main(){
int num;
int finalNum;
int dado;
scanf("%d",&num);
if(num>=42){
finalNum = teste1(num);
if(finalNum != 42){
}
}
printf("%d",finalNum);
}
int teste1(int num){
int newNum;
int once;
int i;
int count;
count = 0;
once = 0;
if(once == 0){
newNum = num;
printf("%d,%d\n",newNum,num);
once = 1;
}
if(newNum >=42){
if(newNum % 2 == 0){
newNum = teste1(newNum-(newNum/2));
}
else if(((newNum % 3 == 0) || (newNum % 4 == 0)) && ((newNum%100)/10)*(newNum%10) > 0){
newNum = teste1(newNum - ((newNum%100)/10)*(newNum%10));
int dado1 = ((newNum%100)/10)*(newNum%10);
/*450*/
}
else if(newNum % 5 == 0){
newNum = teste1(newNum - 42);
}
}
return (newNum);
}
my problem for now is that my code first makes the check if the number is even then if by chance the number is even and multiples of 5 the program will only do the even number check so in the case of the above example my program will not be able to say that it is possible to win. The only way I thought to fix this problem is to run "void Test1" several times, but changing which check I should do first, but since I can’t use any kind of repeating structure in that code I couldn’t think of any smart way to solve the problem other than creating several void with different check seconds. Any idea?