huge ass project . im in trouble. i wanna die. help (C)

iamgayaf15
by iamgayaf15 · 11 posts
6 years ago in Help & Requests
Posted 6 years ago · Author
so i have this huge ass project and the problem is that when i input a char just to check it
the program sort of crashes crashes. (it just prints nonestop)
(it may be something little i didnt see but im quite "blind" to those things
i will never see the problem unless someone points it out)

to point it out . the functions within the 'switch case/break' are completely fine

Code
 /**this function gets a choice and calls to the functions who do the rest of the game
input : choice ,  answer
output : none , when you lose or win it asks you if you wanna play again **/
void levelChoice(void)
{
   int choice = 0;
   
   enum Level
   {
      easy = 1,
      medium,
      hard,
      crazy
   };
   
   scanf("%d", &choice);
   if ((choice < ONE)||(choice < ZERO)||(choice > SIX)) /* i know the default is supposed to do
   this job but as you see when i input a char its still crashes. */
   {
      printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
      do
      {
         getsecretpassword();
         Welcome();
         levelChoice();
      } while (YES == answer);
      fflush(stdin);
      if (NO != answer)
      {
         printf("# # wanna play again?? y for yes and n for no. # # \n");
         scanf("%c", &answer);
      }
      else
      {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
      }   
   }
   else
   {
      switch (choice)
      {
         case easy :
            rounds = EROUNDS;
            while (ZERO != rounds)
            {
               inputEasy();
               fc = hits();
               checkingIfRight();
            
               printf("! ! you have %d rounds left ! !\n", rounds);
            }
         
            fflush(stdin);
            
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
         case medium :
            rounds = MROUNDS;
            while (ZERO != rounds)
            {
               inputMedium();
               fc = hits();
               checkingIfRight();
            
               printf("! ! you have %d rounds left ! !\n", rounds);
            }
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
         case hard :
            rounds = HROUNDS;
            while (ZERO != rounds)
            {
               inputHard();
               fc = hits();
               checkingIfRight();
            }
            fflush(stdin);
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # #");
               scanf("%c", &answer);
            }
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
         case crazy :
            srand(time(NULL));
      
            int Crounds = (rand() % 21) + 5;
            rounds = Crounds;
            while (ZERO != rounds)
            {
               printf("$ $  C R A Z Y  M O D E  $ $ \n\n");
               inputCrazy();
               fc = hits();
               checkingIfRight();
            
            }
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         
         break;
         default :
            printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
            do
            {
               getsecretpassword();
               Welcome();
               levelChoice();
            } while (YES == answer);
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
      }
   }
}
Posted 6 years ago · Author
Don Von Alpha Dom wrote:
I think your variable "answer" is out of scope of your do while loop. Does this program have any global variables or global constants declared? I do not see any.


answer is a global variable actually
those are my global variables:

Code
int fc = 0; /// calls some of the functions 

int rounds = 0;
int guesses = 0;

char digit1 = '0'; /// generates the secret password
char digit2 = '0';
char digit3 = '0';
char digit4 = '0';

char digitA = '0'; /// input guess
char digitB = '0';
char digitC = '0';
char digitD = '0';

char answer = '0'; ///
Posted 6 years ago
@iamgayaf15


Just so you know, the code box with custom formatting doesn't work anymore. Just use a normal code box (without the language or file name).
Posted 6 years ago · Author
@Don Von Alpha Dom


it prints infinitely the Welcome(); function .

the welcome function doesn't have anything too complicated it just prints the rules.

and
@DataMine

thanks!!
Posted 6 years ago · Author
i will just,

give the whole script.

Code
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h> // getch() and putch() actions

#define ONE 1
#define TWO 2
#define THREE 3
#define FOUR 4
#define FIVE 5
#define SIX 6

#define ZERO 0
#define TEN 10

#define EROUNDS 20
#define MROUNDS 15
#define HROUNDS 10

#define YES 'y'
#define NO 'n'

#define FOURTY_EIGHT 48
#define FIFTY_FOUR 56

#define END 2147483647
#define MEND -2147483647

void getsecretpassword(void);
void Welcome(void);
void levelChoice(void);
void inputEasy(void);
void inputMedium(void);
void inputHard(void);
void inputCrazy(void);
int vadilityOfguess(void);
int misses(void);
int hits(void);
void checkingIfRight(void);

/// this is a more succesful code ,

int fc = 0; ///

int rounds = 0; ///
int guesses = 0; ///

char digit1 = '0'; ///
char digit2 = '0';
char digit3 = '0';
char digit4 = '0';

char digitA = '0'; ///
char digitB = '0';
char digitC = '0';
char digitD = '0';

char answer = '0'; ///

int main(void) // credit card secret password guesser
{
   do
   {
      getsecretpassword();
      Welcome();
      levelChoice();
   } while (YES == answer);
   
      
   system("pause");
   printf("\n");
   
   return 0;
}
/**this function is deciding the password. it changes every time because it is a game not the real thing
input : none
output : none **/
void getsecretpassword(void)
{
   srand(time(NULL));

   digit1 = (rand()% 6) + 1;

   digit2 = (rand()% 6) + 1;

   digit3 = (rand()% 6) + 1;

   digit4 = (rand()% 6) + 1;

   while ((digit1 == digit2)||(digit1 == digit3)||(digit1 == digit4)||(digit2 == digit3)||(digit3 == digit4)||(digit2 == digit4))
   {
      digit1 = (rand()% 6) + 1;

      digit2 = (rand()% 6) + 1;

      digit3 = (rand()% 6) + 1;

      digit4 = (rand()% 6) + 1;
   }
   
   digit1 += 48;
   digit2 += 48;
   digit3 += 48;
   digit4 += 48;
}



/** welcomes the user to the code breaker
input : none
output : none  **/
void Welcome(void)
{
   printf("! ! w e l c o m e      t o         m a g s h i m i m       c o d e - b r e a k e r ! ! \n\n\n");
   printf("there is a secret number for pancratius credit card \n");
   printf(" T H E     D E S C E N T A N D     O F     A N T I O C H U S \n");
   printf("your mission is to  ! !S T O P! ! him by revealing his secret password \n");
   printf("the R U L E S are quite simple \n\n");
   printf("in each round you just need to reveal his password which consists of 4 digits \n");
   printf("! ! After every guess you'll receive two hints about the password ! ! \n\n");
   printf("# # H I T S :   The number of digits in your guess which were C O M P L E T E L Y right . # # \n");
   printf("# # M I S S E S : The number of digits in your guess which D O belong to the password but were missplaced . # # \n\n\n");
   printf("! ! choose your level of difficulty ! ! \n\n");
   printf("1.) -easy- 20 rounds \n");
   printf("2.) =medium= 15 rounds \n");
   printf("3.) #hard# 10 rounds \n");
   printf("4.) *crazy* \n\n\n");
}

/**this function gets a choice and calls to the functions who do the rest of the game
input : choice ,  answer
output : none , when you lose or win it asks you if you wanna play again **/
void levelChoice(void)
{
   int choice = 0;
   
   enum Level
   {
      easy = 1,
      medium,
      hard,
      crazy
   };
   
   scanf("%d", &choice);
   if ((choice < ONE)||(choice < ZERO)||(choice > SIX)) /* i know the default is supposed to do
   this job but as you see when i input a char its still crashes. */
   {
      printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
      do
      {
         getsecretpassword();
         Welcome();
         levelChoice();
      } while (YES == answer);
      fflush(stdin);
      if (NO != answer)
      {
         printf("# # wanna play again?? y for yes and n for no. # # \n");
         scanf("%c", &answer);
      }
      else
      {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
      }   
   }
   else
   {
      switch (choice)
      {
         case easy :
            rounds = EROUNDS;
            while (ZERO != rounds)
            {
               inputEasy();
               fc = hits();
               checkingIfRight();
            
               printf("! ! you have %d rounds left ! !\n", rounds);
            }
         
            fflush(stdin);
            
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
         case medium :
            rounds = MROUNDS;
            while (ZERO != rounds)
            {
               inputMedium();
               fc = hits();
               checkingIfRight();
            
               printf("! ! you have %d rounds left ! !\n", rounds);
            }
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
         case hard :
            rounds = HROUNDS;
            while (ZERO != rounds)
            {
               inputHard();
               fc = hits();
               checkingIfRight();
            }
            fflush(stdin);
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # #");
               scanf("%c", &answer);
            }
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
         case crazy :
            srand(time(NULL));
      
            int Crounds = (rand() % 21) + 5;
            rounds = Crounds;
            while (ZERO != rounds)
            {
               printf("$ $  C R A Z Y  M O D E  $ $ \n\n");
               inputCrazy();
               fc = hits();
               checkingIfRight();
            
            }
            if (ZERO == rounds)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         
         break;
         default :
            printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
            do
            {
               getsecretpassword();
               Welcome();
               levelChoice();
            } while (YES == answer);
            fflush(stdin);
            if (NO != answer)
            {
               printf("# # wanna play again?? y for yes and n for no. # # \n");
               scanf("%c", &answer);
            }
            else
            {
               printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
            }
         break;
      }
   }
}

/** function1 (inputEasy, inputMedium, inputHard, inputCrazy)
input : a number that consists of 4 digits (the user has 4 chances)
a char when there are no rounds if the user wants to play again (y or n)
output :  none , and prints questions if the user wants to play again + a 'bye bye' **/
void inputEasy(void)
{
   printf("! ! enter your guess ! ! \n\n");
   
   digitA = getche();
   digitB = getche();
   digitC = getche();
   digitD = getche();
   
   fc = misses();
   
   guesses++;
   rounds--;
}

void inputMedium(void)
{
   printf("! ! enter your guess ! ! \n\n");
   
   digitA = getche();
   digitB = getche();
   digitC = getche();
   digitD = getche();

   
   fc = misses();
   
   guesses++;
   rounds--;
}

void inputHard(void)
{
   printf("! ! enter your guess ! ! \n\n");
   
   digitA = getche();
   digitB = getche();
   digitC = getche();
   digitD = getche();
   
   fc = misses();
   
   guesses++;
   rounds--;
}

void inputCrazy(void)
{   
   printf("! ! enter your guess ! ! \n\n");
   
   digitA = getche();
   digitB = getche();
   digitC = getche();
   digitD = getche();
   
   if (ZERO < vadilityOfguess)
   {
      fc = misses();
   }
   
   guesses++;
   rounds--;
}

int vadilityOfguess(void)
{
   int ok = 0;
   
   if ((FOURTY_EIGHT < digitA)||(FOURTY_EIGHT < digitB)||(FOURTY_EIGHT < digitC)||(FOURTY_EIGHT < digitD))
   {
      ok++;
   }
   if ((FIFTY_FOUR >= digitA)||(FIFTY_FOUR >= digitB)||(FIFTY_FOUR >= digitC)||(FIFTY_FOUR >= digitD))
   {
      ok++;
   }
   else
   {
      ok = 0;
   }
   
   return ok;
}



/**this function calculates the misses without the hits
so it would be easier to fix the misses and hits in a different function
input : none
output : none (if the digits in the guess are ok)
and if not it prints that the guess isnt legal and it returns to the start basically **/
int misses(void)
{
   int miss = 0;
   
   if ((digitB   == digit1)||(digitC == digit1)||(digitD == digit1))
   {
      miss++;
   }
   
   if ((digitA == digit2)||(digitC == digit2)||(digitD == digit2))
   {
      miss++;
   }
   
   if ((digitA == digit3)||(digitB == digit3)||(digitD == digit3))
   {
      miss++;
   }
   if ((digitA == digit4)||(digitB == digit4)||(digitC == digit4))
   {
      miss++;
   }
   
   return miss;
}

/** this function
input :
output :**/
int hits(void)
{
   int hit = 0;
   
   if (digitA == digit1)
   {
      hit++;
   }
   
   if (digitB == digit2)
   {
      hit++;
   }
   
   if (digitC == digit3)
   {
      hit++;
   }
   
   if (digitD == digit4)
   {
      hit++;
   }
   return hit;
}

/** this function
input : none
output : if the number we guessed is right or not and if not which digits were right **/
void checkingIfRight(void)
{
   int hit = hits();
   int miss = misses();
   
   if (FOUR == hit)
   {
      printf(" damn it your guess was right :(( \n");
      printf("it took you %d rounds \n", guesses);
   }
   else if (FOUR != hit)
   {
      printf(" haha human your guess is wrong but , you have %d misses and %d hits \n", miss, hit);
   }
   else if ((FOUR != hit)&&(ZERO != miss))
   {
      printf(" pfffffffft you're COMPLETELY wrong . 0 misses and 0 hits \n");
   }
}
Posted 6 years ago
You did not initialize cRounds. Here is a copy of how I got it working on my end:

Code
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h> // getch() and putch() actions

#define ONE 1
#define TWO 2
#define THREE 3
#define FOUR 4
#define FIVE 5
#define SIX 6

#define ZERO 0
#define TEN 10

#define EROUNDS 20
#define MROUNDS 15
#define HROUNDS 10

#define YES 'y'
#define NO 'n'

#define FOURTY_EIGHT 48
#define FIFTY_FOUR 56

#define END 2147483647
#define MEND -2147483647

void getsecretpassword(void);
void Welcome(void);
void levelChoice(void);
void inputEasy(void);
void inputMedium(void);
void inputHard(void);
void inputCrazy(void);
int vadilityOfguess(void);
int misses(void);
int hits(void);
void checkingIfRight(void);

/// this is a more succesful code ,

int fc = 0; ///

int rounds = 0; ///
int guesses = 0; ///

char digit1 = '0'; ///
char digit2 = '0';
char digit3 = '0';
char digit4 = '0';

char digitA = '0'; ///
char digitB = '0';
char digitC = '0';
char digitD = '0';

char answer = '0'; ///

int Crounds = 0;

int main(void) // credit card secret password guesser
{
   do
   {
      getsecretpassword();
      Welcome();
      levelChoice();
   } while (YES == answer);


   system("pause");
   printf("\n");

   return 0;
}
/**this function is deciding the password. it changes every time because it is a game not the real thing
input : none
output : none **/
void getsecretpassword(void)
{
   srand(time(NULL));

   digit1 = (rand() % 6) + 1;

   digit2 = (rand() % 6) + 1;

   digit3 = (rand() % 6) + 1;

   digit4 = (rand() % 6) + 1;

   while ((digit1 == digit2) || (digit1 == digit3) || (digit1 == digit4) || (digit2 == digit3) || (digit3 == digit4) || (digit2 == digit4))
   {
      digit1 = (rand() % 6) + 1;

      digit2 = (rand() % 6) + 1;

      digit3 = (rand() % 6) + 1;

      digit4 = (rand() % 6) + 1;
   }

   digit1 += 48;
   digit2 += 48;
   digit3 += 48;
   digit4 += 48;
}



/** welcomes the user to the code breaker
input : none
output : none  **/
void Welcome(void)
{
   printf("! ! w e l c o m e      t o         m a g s h i m i m       c o d e - b r e a k e r ! ! \n\n\n");
   printf("there is a secret number for pancratius credit card \n");
   printf(" T H E     D E S C E N T A N D     O F     A N T I O C H U S \n");
   printf("your mission is to  ! !S T O P! ! him by revealing his secret password \n");
   printf("the R U L E S are quite simple \n\n");
   printf("in each round you just need to reveal his password which consists of 4 digits \n");
   printf("! ! After every guess you'll receive two hints about the password ! ! \n\n");
   printf("# # H I T S :   The number of digits in your guess which were C O M P L E T E L Y right . # # \n");
   printf("# # M I S S E S : The number of digits in your guess which D O belong to the password but were missplaced . # # \n\n\n");
   printf("! ! choose your level of difficulty ! ! \n\n");
   printf("1.) -easy- 20 rounds \n");
   printf("2.) =medium= 15 rounds \n");
   printf("3.) #hard# 10 rounds \n");
   printf("4.) *crazy* \n\n\n");
}

/**this function gets a choice and calls to the functions who do the rest of the game
input : choice ,  answer
output : none , when you lose or win it asks you if you wanna play again **/
void levelChoice(void)
{
   int choice = 0;

   enum Level
   {
      easy = 1,
      medium,
      hard,
      crazy
   };

   scanf("%d", &choice);
   if ((choice < ONE) || (choice < ZERO) || (choice > SIX)) /* i know the default is supposed to do
                                              this job but as you see when i input a char its still crashes. */
   {
      printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
      do
      {
         getsecretpassword();
         Welcome();
         levelChoice();
      } while (YES == answer);
      fflush(stdin);
      if (NO != answer)
      {
         printf("# # wanna play again?? y for yes and n for no. # # \n");
         scanf("%c", &answer);
      }
      else
      {
         printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
      }
   }
   else
   {
      switch (choice)
      {
      case easy:
         rounds = EROUNDS;
         while (ZERO != rounds)
         {
            inputEasy();
            fc = hits();
            checkingIfRight();

            printf("! ! you have %d rounds left ! !\n", rounds);
         }

         fflush(stdin);

         if (ZERO == rounds)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         fflush(stdin);
         if (NO != answer)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         else
         {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
         }
         break;
      case medium:
         rounds = MROUNDS;
         while (ZERO != rounds)
         {
            inputMedium();
            fc = hits();
            checkingIfRight();

            printf("! ! you have %d rounds left ! !\n", rounds);
         }
         if (ZERO == rounds)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         fflush(stdin);
         if (NO != answer)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         else
         {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
         }
         break;
      case hard:
         rounds = HROUNDS;
         while (ZERO != rounds)
         {
            inputHard();
            fc = hits();
            checkingIfRight();
         }
         fflush(stdin);
         if (ZERO == rounds)
         {
            printf("# # wanna play again?? y for yes and n for no. # #");
            scanf("%c", &answer);
         }
         if (NO != answer)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         else
         {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
         }
         break;
      case crazy:
         srand(time(NULL));

         Crounds = (rand() % 21) + 5;
         rounds = Crounds;
         while (ZERO != rounds)
         {
            printf("$ $  C R A Z Y  M O D E  $ $ \n\n");
            inputCrazy();
            fc = hits();
            checkingIfRight();

         }
         if (ZERO == rounds)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         fflush(stdin);
         if (NO != answer)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         else
         {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
         }

         break;

      default:
         printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
         do
         {
            getsecretpassword();
            Welcome();
            levelChoice();
         } while (YES == answer);
         fflush(stdin);
         if (NO != answer)
         {
            printf("# # wanna play again?? y for yes and n for no. # # \n");
            scanf("%c", &answer);
         }
         else
         {
            printf("@ @ oh well  B Y E B Y E  :(( @ @ \n");
         }
         break;
      }
   }
}

/** function1 (inputEasy, inputMedium, inputHard, inputCrazy)
input : a number that consists of 4 digits (the user has 4 chances)
a char when there are no rounds if the user wants to play again (y or n)
output :  none , and prints questions if the user wants to play again + a 'bye bye' **/
void inputEasy(void)
{
   printf("! ! enter your guess ! ! \n\n");

   digitA = _getche();
   digitB = _getche();
   digitC = _getche();
   digitD = _getche();

   fc = misses();

   guesses++;
   rounds--;
}

void inputMedium(void)
{
   printf("! ! enter your guess ! ! \n\n");

   digitA = _getche();
   digitB = _getche();
   digitC = _getche();
   digitD = _getche();


   fc = misses();

   guesses++;
   rounds--;
}

void inputHard(void)
{
   printf("! ! enter your guess ! ! \n\n");

   digitA = _getche();
   digitB = _getche();
   digitC = _getche();
   digitD = _getche();

   fc = misses();

   guesses++;
   rounds--;
}

void inputCrazy(void)
{
   printf("! ! enter your guess ! ! \n\n");

   digitA = _getche();
   digitB = _getche();
   digitC = _getche();
   digitD = _getche();

   if (ZERO < vadilityOfguess)
   {
      fc = misses();
   }

   guesses++;
   rounds--;
}

int vadilityOfguess(void)
{
   int ok = 0;

   if ((FOURTY_EIGHT < digitA) || (FOURTY_EIGHT < digitB) || (FOURTY_EIGHT < digitC) || (FOURTY_EIGHT < digitD))
   {
      ok++;
   }
   if ((FIFTY_FOUR >= digitA) || (FIFTY_FOUR >= digitB) || (FIFTY_FOUR >= digitC) || (FIFTY_FOUR >= digitD))
   {
      ok++;
   }
   else
   {
      ok = 0;
   }

   return ok;
}



/**this function calculates the misses without the hits
so it would be easier to fix the misses and hits in a different function
input : none
output : none (if the digits in the guess are ok)
and if not it prints that the guess isnt legal and it returns to the start basically **/
int misses(void)
{
   int miss = 0;

   if ((digitB == digit1) || (digitC == digit1) || (digitD == digit1))
   {
      miss++;
   }

   if ((digitA == digit2) || (digitC == digit2) || (digitD == digit2))
   {
      miss++;
   }

   if ((digitA == digit3) || (digitB == digit3) || (digitD == digit3))
   {
      miss++;
   }
   if ((digitA == digit4) || (digitB == digit4) || (digitC == digit4))
   {
      miss++;
   }

   return miss;
}

/** this function
input :
output :**/
int hits(void)
{
   int hit = 0;

   if (digitA == digit1)
   {
      hit++;
   }

   if (digitB == digit2)
   {
      hit++;
   }

   if (digitC == digit3)
   {
      hit++;
   }

   if (digitD == digit4)
   {
      hit++;
   }
   return hit;
}

/** this function
input : none
output : if the number we guessed is right or not and if not which digits were right **/
void checkingIfRight(void)
{
   int hit = hits();
   int miss = misses();

   if (FOUR == hit)
   {
      printf(" damn it your guess was right :(( \n");
      printf("it took you %d rounds \n", guesses);
   }
   else if (FOUR != hit)
   {
      printf(" haha human your guess is wrong but , you have %d misses and %d hits \n", miss, hit);
   }
   else if ((FOUR != hit) && (ZERO != miss))
   {
      printf(" pfffffffft you're COMPLETELY wrong . 0 misses and 0 hits \n");
   }
}
Posted 6 years ago · Author
thanks you all
and my dumb ass should've made the enum easy start from 49
and then get the choice by char


S H R E K
B L E S S E S
Y O U
A L L

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT
Select a forum Protection     Help & Support     Introductions     Mafia News     IMVU News General Discussion     IMVU Lounge        IMVU Series / Roleplaying        Social Games     Mafia Market     Mafia Tools        Premium IMVU Tools        Off Topic Tools     Off Topic     Contests Creator Corner     Graphics Design        Photoshop        GIMP     Basic Creator Help     Catalog And Product Showcase     3D Meshing        3Ds Max        Sketchup        Blender Gangsters with Connections     White Hat Activities        Google Hacking        Trackers Programming Corner     Coding        Python        .Net (C#, VB, etc)        Flash        JAVA        Autoit        Batch        HTML & CSS        Javascript        PHP        Other        IMVU Homepage Codes           General           About me Panel           Messages Panel           Special Someone Panel           Visitors Panel           New Products Panel           Rankings Panel           Wishlist Panel           My Badges Panel           Outfits Panel           Url Panel           Groups Panel           Slideshow Panel           My Room Panel           Sandbox panel           Layouts     Help & Requests Free Credits     Approved Methods     Submit Methods Free Money     Approved Methods     Submit Methods Adult Corner     Get Mafia AP Here     AP Lounge        AP Social Games        Casual Dating Tips     IMVU Slave Market & Escorts