int main(int argc, const char * argv[])
{
@autoreleasepool
{
int sides; //Variable used to store the number of sides on the dice
BOOL rollOn = TRUE; //Holds a true or false value which controls the continue roll option
char keepRolling = 'n'; //Variable used when asking the user wether they would to keep rolling
while (rollOn == TRUE)
{
NSLog(@"How many sides does your dice have?"); //Asks user how many sides the dice has
scanf("%i", &sides); //Accepts input from keyboard and stores it into variable sides
int roll = arc4random() % sides + 1; //Returns a random value based on how many sides the dice has
NSLog(@"You rolled a %i", roll); //Prints your roll to the screen
NSLog(@"Would you like to roll another dice? y / n"); //Asks user if they want to keep rolling
keepRolling =fgetc(stdin);
if (keepRolling == 'n' || keepRolling == 'N')
{
rollOn = FALSE;
}
else
rollOn = TRUE;
}
}
return 0;
}
Should I be using a different kind of look for this, or is my code just wrong?
Sorry, this is in the wrong forum, I didn't notice the Objective-C subforum, could a mod move this.

New Topic/Question
Reply


MultiQuote





|