Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Guess-the-number/Objective-C/guess-the-number.m
Normal file
39
Task/Guess-the-number/Objective-C/guess-the-number.m
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
|
||||
@autoreleasepool {
|
||||
|
||||
NSLog(@"I'm thinking of a number between 1 - 10. Can you guess what it is?\n");
|
||||
|
||||
int rndNumber = arc4random_uniform(10) + 1;
|
||||
|
||||
// Debug (Show rndNumber in console)
|
||||
//NSLog(@"Random number is %i", rndNumber);
|
||||
|
||||
int userInput;
|
||||
|
||||
do {
|
||||
|
||||
NSLog(@"Input the number below\n");
|
||||
scanf("%i", &userInput);
|
||||
|
||||
if (userInput > 10) {
|
||||
|
||||
NSLog(@"Please enter a number less than 10\n");
|
||||
}
|
||||
|
||||
if (userInput > 10 || userInput != rndNumber) {
|
||||
|
||||
NSLog(@"Your guess %i is incorrect, please try again", userInput);
|
||||
|
||||
} else {
|
||||
|
||||
NSLog(@"Your guess %i is correct!", userInput);
|
||||
}
|
||||
|
||||
} while (userInput > 10 || userInput != rndNumber);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue