Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added HangPerson/.DS_Store
Binary file not shown.
42 changes: 37 additions & 5 deletions HangPerson/HangPerson/main.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
//
// main.m
// HangPerson
// HangManGame
//
// Created by Michael Kavouras on 6/15/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
// Created by Jason Wang on 6/17/15.
// Copyright (c) 2015 Jason Wang. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// Start Code HERE
char hangManWord[8] = "zodiacs";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to specify a size (eg. [8]) if you are initializing the variable with a value (eg "zodiacs"); You can just do:

char hangManWord[] = "zodiacs";

char underLineWord[8] = "_______";

// code goes here...

int totalLife = 20;
char guess;
int numGuess;
int replace = 7;


for (numGuess = 0; numGuess < totalLife; numGuess++) {
printf("Please guess a Letter: ");
scanf("%c", &guess);
for (int i = 0; i < 7; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the number 7 is a bit specific. Instead you could use strlen(hangManWord) or sizeof(hangManWord).

if (guess == hangManWord[i]) {
replace--;
char temp;
temp = hangManWord[i];
hangManWord[i] = underLineWord[i];
underLineWord[i] = temp;
printf("%s \n", underLineWord);
}
}
if (replace == 0){
break;
}

}
if (replace == 0) {
printf("You WON");
} else {
printf("Sorry you LOST");
}

// End Code HERE
}
return 0;
}