Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void guesses(void)
- {
- int i = 0;
- int iprint = 0;
- char gone, gtwo, gthree, gfour;
- int none, ntwo, nthree, nfour, miss, hit = 0;
- for(i = 0; i <= globalguess - 1; i++ )//stops when i = globalguess because the mode
- {
- hit = 0;
- miss = 0;
- int guesscheck = globalguess - i;
- printf("write your guess(1-6 only,no ENTER is needed)\n");
- if(globalchoice == 4)//if its crazy mode print crazy mode
- {
- printf("CRAZY MODE!!!\n");
- }
- else
- {
- printf("%d guesses left\n", guesscheck);//print how many guesses you still have
- }
- gone = (int) getch() - 48;
- printf("%d", gone);
- gtwo = (int) getch() - 48;
- printf("%d", gtwo);
- gthree = (int) getch() - 48;
- printf("%d", gthree);
- gfour = (int) getch() - 48 ;
- printf("%d", gfour);
- //get the guess from the user
- if(gone != 1 && gone != 2 && gone != 3 && gone != 4 && gone != 5 && gone != 6 )
- {
- printf("\n1-6 only!!\n");
- i--;
- guesscheck = globalguess + i;
- }
- else if( gtwo != 1 && gtwo != 2 && gtwo != 3 && gtwo != 4 && gtwo != 5 && gtwo != 6 )
- {
- printf("\n1-6 only!!\n");
- i--;
- guesscheck = globalguess + i;
- }
- else if( gthree != 1 && gthree != 2 && gthree != 3 && gthree != 4 && gthree != 5 && gthree != 6 )
- {
- printf("\n1-6 only!!\n");
- i--;
- guesscheck = globalguess + i;
- }
- else if( gfour != 1 && gfour != 2 && gfour != 3 && gfour != 4 && gfour != 5 && gfour != 6 )
- {
- printf("\n1-6 only!!\n");
- i--;
- guesscheck = globalguess + i;
- }
- // checking if the numbers aren't between 1-6
- else
- {
- none = (globalrand / 100) / 10;
- ntwo = (globalrand / 100) % 10;
- nthree = (globalrand / 10) % 10;
- nfour = globalrand % 10;
- //saperate the numbers to check the miss and hit
- if(gone == none)
- {
- hit = hit + 1;
- }
- if(gtwo == ntwo)
- {
- hit = hit + 1;
- }
- if(gthree == nthree)
- {
- hit = hit + 1;
- }
- if(gfour == nfour)
- {
- hit = hit + 1;
- }
- if(gone == ntwo || gone == nthree || gone == nfour)
- {
- miss = miss + 1;
- }
- if(gtwo == none || gtwo == nthree || gtwo == nfour)
- {
- miss = miss + 1;
- }
- if(gthree == ntwo || gthree == none || gthree == nfour)
- {
- miss = miss + 1;
- }
- if(gfour == ntwo || gfour == nthree || gfour == none)
- {
- miss = miss + 1;
- }
- //checking if there is hits or misses
- iprint = i + 1;
- if(hit == 4)
- {
- i = globalguess;
- }
- //checking if the hits number is 4 if yes stop the loop
- else
- {
- printf("\nyou got %d HITS %d MISS\n", hit, miss);
- }
- } //print how many hits and how many miss
- }
- // after the loop
- if(i != globalguess)//check if the user won or lose
- {
- printf("\n 4 HITS YOU WON!!!\nIt took you only %d guesses, you are a professional code breaker!\n\n", iprint);//win
- }
- else
- {
- printf("\nOOOOHHHH!!! prancatius won and bought all of Hankkah's gifts\nnothing left for you....\nthe secret code password was %d\n\n", globalrand);//lose
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement