I am new to C programming and have an assignment to write a Slot Machine programme using structs. I am nearing the end of the code and everything is working fin apart from this one seemingly simple fuction:
float NewCred(){
printf("%s %s %s", sm.fruit1.face, sm.fruit2.face, sm.fruit3.face);
if(sm.fruit1.face == sm.fruit2.face && sm.fruit2.face == sm.fruit3.face){
printf("\nFULL HOUSE!!! You win %.2f more credits!\n", bet);
cred += (bet);
}
else if(sm.fruit1.face == sm.fruit2.face || sm.fruit2.face == sm.fruit3.face || sm.fruit1.face == sm.fruit3.face){
printf("\nHalf House! You win %.2f more credits!\n", bet/2);
cred += (bet/2);
}
else{
printf("\nUnlucky! You lose %.2f credits...\n", bet);
cred -= bet;
}
return cred;
}
The first printf line was just a test to see if the strings for sm.fruit[x].face had been passed into the function, whcih they had. However, no matter what the three values for sm.fruit[x] are, the function always executes the final else statement and I cannot figure out why.
Thank you for any help in advance.
OUTPUT:
ORANGE PEAR ORANGE
Unlucky! You lose 8.00 credits...
You now have 2.00 credits.