i'm trying to make a slot machine type thing and i wanted to assign the randomly generated numbers to certain symbols like 1 = cherry, 2 = bell and so on so i could print out the results in symbol form at the end.
i tried putting the symbols as strings in an array and assigning the numbers to the elements in the array in each slot functions but it didn't work out... is there a way to do this?
here's the code i've written so far, minus the array attempts. any suggestions would be helpful! :D
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int slotOne(int randOne)
{
randOne = rand() % 4 + 1;
return randOne;
}
int slotTwo(int randTwo)
{
randTwo = rand() % 4 + 1;
return randTwo;
}
int slotThree(int randThree)
{
randThree = rand() % 4 + 1;
return randThree;
}
int main()
{
int x, one, two, three;
srand(time(NULL));
one = slotOne(x);
two = slotTwo(x);
three = slotThree(x);
printf("%d - %d - %d\n", one, two, three);
//checks to see if they won
if (one == two && two == three)
{
printf("You won the JACKPOT!\n");
}
else if (one == two || two == three || one == three)
{
printf("You won!\n");
}
else
{
printf("Sorry, you lost.\n");
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire