-
-
Save 98chimp/9ba6e32fa18180ee6e48 to your computer and use it in GitHub Desktop.
Revisions
-
98chimp revised this gist
Mar 11, 2015 . 1 changed file with 11 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,14 +46,11 @@ void question() { question2 = arc4random() % 21; if (turn % 2 == 0) { printf("%c's turn: what is %d + %d?\n", player1.name, question1, question2); } else { printf("%c's turn: what is %d + %d?\n", player2.name, question1, question2); } scanf("%d", &answer); if (question1 + question2 == answer) { @@ -65,19 +62,23 @@ void question() { else { player2.points ++; } printf("%c's score: %d points; %d lives\n", player1.name, player1.points, player1.lives); printf("and %c's score: %d points; %d lives\n", player2.name, player2.points, player1.lives); } else { printf("wrong!\n"); correct = false; if (turn % 2 == 0) { player1.lives --; } else { player2.lives --; } printf("%c's score: %d points; %d lives\n", player1.name, player1.points, player1.lives); printf("and %c's score: %d points; %d lives\n", player2.name, player2.points, player2.lives); } turn++; if (input == 2) { exit(0); @@ -115,10 +116,10 @@ int main() { question(); } if (player1.lives == 0) { printf("%c has won the game!\n", player2.name); } else { printf("%c has won the game!\n", player1.name); } } -
98chimp revised this gist
Mar 11, 2015 . 1 changed file with 108 additions and 45 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,63 +1,126 @@ // // main.c // Guessing Game // // Created by Shahin on 2015-03-10. // Copyright (c) 2015 98% Chimp. All rights reserved. // #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> bool isRunning = true; typedef struct { int lives; int points; char name; } Player; Player resetPlayer (int lives, int points, char name); Player player1; Player player2; Player currentPlayer; int input, answer, question1, question2; int turn = 0; bool correct; void setNames() { printf("Welcome to our Math Game!\n"); printf("Please enter your name\n"); scanf("%s", &player1.name); player1.points = 0; player1.lives = 3; printf("Please enter opponent's name\n"); scanf("%s", &player2.name); player2.points = 0; player2.lives = 3; } void question() { question1 = arc4random() % 21; question2 = arc4random() % 21; if (turn % 2 == 0) { printf("%d turn: what is %d + %d?\n", player1.name, question1, question2); } else { printf("%d turn: what is %d + %d?\n", player2.name, question1, question2); } turn++; scanf("%d", &answer); if (question1 + question2 == answer) { printf("correct!\n"); correct = true; if (turn % 2 == 0) { player1.points ++; } else { player2.points ++; } printf("%c's score is: %d\n", player1.name, player1.points); printf("and %c's score is: %d\n", player2.name, player2.points); } else { printf("wrong!\n "); correct = false; if (turn % 2 == 0) { player1.lives --; } else { player2.lives --; } } if (input == 2) { exit(0); } } int mainMenu(int input){ printf("Welcome to our Math Game!\n"); printf("Press 1 to start the game\n"); printf("Press 2 to exit\n"); scanf("%d", &input); if (input == 2) { return isRunning = false; } else if (input == 1) { return isRunning = true; } return 0; } int main() { #pragma mark isRunning while (isRunning) { mainMenu(input); setNames(); while (player1.lives > 0 && player2.lives > 0) { question(); } if (player1.lives == 0) { printf("%c has won the game!/n", player2.name); } else { printf("%c has won the game!/n", player1.name); } } return 0; } -
98chimp revised this gist
Mar 11, 2015 . 1 changed file with 47 additions and 96 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,112 +1,63 @@ // // main.c // Adam // // Created by Shahin on 2015-03-09. // Copyright (c) 2015 98% Chimp. All rights reserved. // #include <stdio.h> #include <stdbool.h> #include <ctype.h> #include <string.h> int main(int argc, const char * argv[]) { // insert code here... int a = 1; while (a == 1) { printf("Please type in your question for Adam (type exit to discontinue): "); char input[]=""; rewind(stdin); scanf("%[^\n]", input); long length = strlen(input); long len = length - 1; char *s1 = &input[len]; char *s2 = "?"; char *exit = "exit"; bool uppercase = true; if (strcmp(input, exit) == 0) { printf("Yo yo!\n"); a = 2; break; } else if (length > 0) { for (int i = 0; i < length; i++) { if (!((input[i] >= 65 && input[i] <= 90) || input[i] == 32)) { uppercase = false; break; } } if (uppercase) { printf("Woah, chill out!\n"); } else if (strcmp(s1, s2) == 0) { printf("Sure!\n"); } else { printf("Whatever!\n"); } } else { printf("Fine. Be that way!\n"); } } return 0; } -
98chimp created this gist
Mar 11, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,112 @@ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> bool isRunning = true; typedef struct { int lives; int points; char name; } Player; Player resetPlayer (int lives, int points, char name); Player player1; Player player2; int input, answer, question1, question2, wrong; void setNames() { printf("Welcome to our Math Game!\n"); printf("Please enter player 1's name\n"); scanf("%s", &player1.name); printf("Please enter player 2's name\n"); scanf("%s", &player2.name); } void question () { bool turn = true; Player currentPlayer; if (turn) { currentPlayer = player1; } else {currentPlayer = player2;} question1 = arc4random() %21; question2 = arc4random() %21; if (input == 1) { printf("%d: Question 1: %d + %d\n",currentPlayer.name, question1, question2); scanf("%d", &answer); if (question1 + question2 == answer) { printf("correct!\n"); wrong = 0; } else { printf("wrong!\n "); wrong = 1; } } if (input == 2) { exit(0); } } int mainMenu(int input){ printf("Welcome to our Math Game!\n"); printf("Press 1 to start the game\n"); printf("Press 2 to exit\n"); scanf("%d", &input); if (input == 2) { isRunning = false; } else if (input == 1) { question(); } return 0; } //Player resetPlayer (Player) { // // //} int main() { #pragma mark isRunning while (isRunning) { mainMenu(input); if (mainMenu(wrong = 1)) { mainMenu(input); } while (player1.lives > 0&&player2.lives > 0) { } } return 0; }