<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. READ inputs
  3.  
  4. IF the number of Pidgies is not a whole number OR more than 0 THEN
  5.    PRINT error message to tell the user that the input is invalid
  6. END IF
  7. IF the number of Candies is not a whole number OR more than 0 THEN
  8.    PRINT error message to tell the user that the input is invalid
  9. END IF
  10. IF the number of Pidgies evolved per 30 mins is not a whole number OR more than 0 THEN
  11.    PRINT error message to tell the user that the input is invalid
  12. END IF
  13. IF any of the inputs was not not a whole number OR more than 0 THEN
  14.    END
  15. END IF
  16.  
  17. IF inputs are not whole numbers greater than 1 THEN
  18.    END PROGRAM
  19. END IF
  20.  
  21. WHILE the number of Pidgies is more than 1 AND the number of Candies is more than or equal to 12
  22.    SUBTRACT 1 from number of Pidgies
  23.    SUBTRACT 12 from number of Candies
  24.    ADD 1 to number of Candies
  25.    ADD 30 minutes to total time
  26.    ADD 1000 to total XP
  27. END WHILE
  28.  
  29. DIVIDE total time by 30 minutes
  30. ROUND UP the answer to find the number of lucky eggs needed
  31.  
  32. PRINT total XP and number of lucky eggs needed
  33. */
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <math.h>
  38. #include <string.h>
  39.  
  40. int main( void )
  41. {
  42.    /* VARIABLES */
  43.    double numPidgey = 0; /* Number of Pidgies */
  44.    double numCandy = 0; /* Number of Candies */
  45.    double numEvoPerEgg = 60; /* Number of Pidgies the user can evolve per Egg duration || Default = 60 */
  46.    double numLuckyEgg = 0; /* Number of lucky eggs */
  47.    double luckyEggDur = 1800; /* Duration of lucky eggs  */
  48.    double totalTime = 0; /* Accumulates the total time taken */
  49.    double luckyEggMult = 2; /* XP multiplier while a lucky egg is in effect */
  50.    double evoXP = 500; /* XP points a player earns for evolving a Pidgey */
  51.    double numEvoCandy = 12; /* Number of Candies to evolve a Pidgey */
  52.    double numEvoCandyReturn = 1; /* Number of Candies returned after evolving a Pidgey */
  53.    double totalXP = 0; /* Accumulates the XP earned */
  54.    
  55.    /* USER INPUT */
  56.    /* Accepts 3 inputs for number of Pidgies, number of Candies and number of evolutions per egg duration */
  57.    /* Only the first 2 are required */
  58.    scanf("%lf %lf %lf", &numPidgey, &numCandy, &numEvoPerEgg);
  59.    
  60.    /* INPUT CHECK */
  61.    /* Calls a function that makes sure all the inputs are valid */
  62.    if(checkInput(numPidgey, numCandy, numEvoPerEgg))
  63.    {
  64.       /* If any of the inputs are invalid then it ends the program*/
  65.       return;
  66.    }
  67.    
  68.    /* CALCULATE XP */
  69.    /* Finds the amount of time taken to evolve 1 Pidgey */
  70.    double timeToEvo = luckyEggDur / numEvoPerEgg;
  71.    
  72.    /* Each loop finds the XP earned for 1 pidgey evolution */
  73.    /* Continues looping until it either has no more Pidgies or not enough candies */
  74.    while(numPidgey > 0 && numCandy >= numEvoCandy)
  75.    {
  76.       numPidgey--;
  77.       /* Removes the number of candies to evolve and adds the number that would be returned */
  78.       numCandy -= (numEvoCandy - numEvoCandyReturn);
  79.       totalTime += timeToEvo;
  80.       totalXP += (evoXP * luckyEggMult);
  81.    }
  82.    
  83.    /* Calculates the number of lucky eggs a user should use */
  84.    /* Rounds up to the next whole number */
  85.    numLuckyEgg += ceil(totalTime / luckyEggDur);
  86.    
  87.    /* PRINT RESULT */
  88.    printf("You can earn %.0lfXP", totalXP);
  89.    printf("\nYou should use %.0lf lucky egg(s)", numLuckyEgg);
  90. }
  91.  
  92.  
  93. /* INPUT CHECK */
  94. /* Checks that all inputs are whole numbers greater or equal to 1 */
  95. /* If any invalid inputs are found it prints useful error messages */
  96. int checkInput(double numPidgey, double numCandy, double numEvoPerEgg)
  97. {
  98.    /* This stores if there is a valid input (0) or not (1) */
  99.    int fail = 0;
  100.    
  101.    /* Performs a modulus calculation on the number of Pidgies, diving by 1 */
  102.    /* If the result is not 1, then the input is not a whole number */
  103.    /* Checks if the number of Pidgies is at least 1 */
  104.    if(fmod(numPidgey, 1) != 0 || numPidgey <= 0)
  105.    {
  106.       fail = 1;
  107.      
  108.       printf("The number of Pidgies must be ");
  109.      
  110.       /* Checks if the input is a whole number */
  111.       /* If it is not it prints the appropriate affix to the message */
  112.       if (fmod(numPidgey, 1) != 0)
  113.       {
  114.          printf("a whole number ");
  115.       }
  116.      
  117.       /* Checks if the input is greater than or equal to 1 */
  118.       /* If it is not it prints the appropriate affix to the message */
  119.       if (numPidgey <= 0)
  120.       {
  121.          printf("greater than or equal to 1");
  122.       }
  123.      
  124.       printf("\n");
  125.    }
  126.    
  127.    /* Performs a modulus calculation on the number of Candies, diving by 1 */
  128.    /* If the result is not 1, then the input is not a whole number */
  129.    /* Checks if the number of Pidgies is at least 1 */
  130.    if(fmod(numCandy, 1) != 0 || numCandy <= 0)
  131.    {
  132.       fail = 1;
  133.      
  134.       printf("The number of Pidgey Candies must be ");
  135.      
  136.       /* Checks if the input is a whole number */
  137.       /* If it is not it prints the appropriate affix to the message */
  138.       if (fmod(numCandy, 1) != 0)
  139.       {
  140.          printf("a whole number ");
  141.       }
  142.      
  143.       /* Checks if the input is greater than or equal to 1 */
  144.       /* If it is not it prints the appropriate affix to the message */
  145.       if (numCandy <= 0)
  146.       {
  147.          printf("greater than or equal to 1");
  148.       }
  149.      
  150.       printf("\n");
  151.    }
  152.    
  153.    /* If this number is not 60 (The default number) then the user must have input something, and it must be checked */
  154.    if(numEvoPerEgg != 60)
  155.    {
  156.       /* Performs a modulus calculation on the number of Evolutions per egg duration, diving by 1 */
  157.       /* If the result is not 1, then the input is not a whole number */
  158.       /* Checks if the number of Pidgies is at least 1 */
  159.       if(fmod(numEvoPerEgg, 1) != 0 || numEvoPerEgg <= 0)
  160.       {
  161.          fail = 1;
  162.      
  163.          printf("The number of Evolutions per Egg must be ");
  164.          
  165.          /* Checks if the input is a whole number */
  166.          /* If it is not it prints the appropriate affix to the message */
  167.          if (fmod(numEvoPerEgg, 1) != 0)
  168.          {
  169.             printf("a whole number ");
  170.          }
  171.          
  172.          /* Checks if the input is greater than or equal to 1 */
  173.          /* If it is not it prints the appropriate affix to the message */
  174.          if (numEvoPerEgg <= 0)
  175.          {
  176.             printf("greater than or equal to 1");
  177.          }
  178.       }
  179.    }
  180.    
  181.    /* Returns if the input has passed or not */
  182.    return fail;
  183. }