improved program flow + added gibberish function
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
4659bbee19
commit
4c7e821e79
52
main.c
52
main.c
@ -1,14 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void print_menu(){
|
void print_menu(){
|
||||||
printf("\n[*] guess a number from 0 to 10\n");
|
printf("\n[*] guess a number from 0 to 10\n");
|
||||||
printf( "[*] press:\n"
|
printf( "[*] press:\n"
|
||||||
"\t1 to play\n"
|
"\t1 to play\n"
|
||||||
"\t2 to try again\n"
|
"\t2 to try again\n"
|
||||||
"\t...or anything else to exit\n");
|
"\t...or anything else to exit\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int lemmego(){
|
int lemmego(){
|
||||||
@ -39,42 +38,38 @@ int get_userguess(){
|
|||||||
while (fgetc(stdin) != '\n'){
|
while (fgetc(stdin) != '\n'){
|
||||||
}
|
}
|
||||||
printf("[*] give me a correct value\n");
|
printf("[*] give me a correct value\n");
|
||||||
printf("[*] stop gibbering around\n");
|
printf("[*] stop gibbering around\n my guess >>> ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void compare_guess_with_reality(int userguess, int reality){
|
void compare_guess_with_reality(int userguess, int reality){
|
||||||
printf("[*] guess was: %d\n", userguess);
|
|
||||||
printf("[*] reality is: %d\n", reality);
|
|
||||||
|
|
||||||
if(userguess == reality){
|
if(userguess == reality){
|
||||||
printf("[*] you won because you've got luck. try me next time!\n");
|
printf("[*] you won because you've got luck. try me next time!\n");
|
||||||
}else if(userguess < reality){
|
}else if(userguess < reality){
|
||||||
printf("[*] you lost!\n");
|
printf("[*] you lost!\n");
|
||||||
|
printf("\thint: your guess was just a tad lower than the secret number\n");
|
||||||
}else{
|
}else{
|
||||||
|
printf("[*] you lost!\n");
|
||||||
|
printf("[i] hint: your guess was just a tad higher than the secret number\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void guess(){
|
void guess(){
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
int userchoice = -1;
|
int userchoice = -1;
|
||||||
|
int nurand = -1;
|
||||||
printf("\nwelcome to the guessing game\n");
|
printf("\nwelcome to the guessing game\n");
|
||||||
|
|
||||||
while (userchoice != 3){
|
while (userchoice != 3){
|
||||||
int userguess = -1;
|
int userguess = -1;
|
||||||
int nurand = -1;
|
|
||||||
int verdict = -1;
|
|
||||||
int ok = -1;
|
int ok = -1;
|
||||||
|
|
||||||
print_menu();
|
print_menu();
|
||||||
|
|
||||||
while(ok != 1){
|
while(ok != 1){
|
||||||
printf("[*] you: ");
|
printf("[*] you >>> ");
|
||||||
ok = scanf("%d", &userchoice);
|
ok = scanf("%d", &userchoice);
|
||||||
if(ok == EOF){
|
if(ok == EOF){
|
||||||
printf("[*] please, come on...\n");
|
printf("[*] please, come on...\n");
|
||||||
@ -82,7 +77,6 @@ void guess(){
|
|||||||
if(ok == 0){
|
if(ok == 0){
|
||||||
while (fgetc(stdin) != '\n'){
|
while (fgetc(stdin) != '\n'){
|
||||||
}
|
}
|
||||||
// printf("[*] give me a correct value next time (an integer)\n");
|
|
||||||
lemmego();
|
lemmego();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -92,20 +86,23 @@ void guess(){
|
|||||||
case 1:
|
case 1:
|
||||||
nurand = get_rand();
|
nurand = get_rand();
|
||||||
printf( "[?] what is your guess then? pick a number from 0 to 10\n" );
|
printf( "[?] what is your guess then? pick a number from 0 to 10\n" );
|
||||||
printf("\tmy guess: ");
|
printf(" my guess >>> ");
|
||||||
|
|
||||||
userguess = get_userguess();
|
userguess = get_userguess();
|
||||||
compare_guess_with_reality(userguess, nurand);
|
compare_guess_with_reality(userguess, nurand);
|
||||||
|
|
||||||
if (verdict == 0){
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
if(nurand == -1){
|
||||||
|
printf("[!] there wasn't a first time yet, mate...\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
printf("[*] guess again\n");
|
printf("[*] guess again\n");
|
||||||
userchoice = 1;
|
printf( "[?] what is your guess then? pick a number from 0 to 10\n" );
|
||||||
|
printf(" my guess >>> ");
|
||||||
|
|
||||||
|
userguess = get_userguess();
|
||||||
|
compare_guess_with_reality(userguess, nurand);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -115,8 +112,23 @@ void guess(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_rand_bs(){
|
||||||
|
printf("\n\n[*] printing rand\n");
|
||||||
|
printf("seed\trand1\trand2\trand3\trand4\trand5\trand6\trand7\n");
|
||||||
|
for (unsigned int i = 1; i < 6; i++){
|
||||||
|
unsigned int seed = i;
|
||||||
|
srand(seed);
|
||||||
|
printf("%d\t", seed);
|
||||||
|
for (int j = 0; j < 7; j++){
|
||||||
|
printf("%d\t", rand() % 101);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
guess();
|
guess();
|
||||||
|
print_rand_bs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user