<mosaic.cnfolio.com>
PROGRAM
  1. /*Pseudocode:
  2. START
  3. Read the 2 input numbers,and optional Y/N character(number of pidgeys, and number of candies, option to use a lucky egg)
  4. IF an input value is missing,
  5. THEN display an error message,
  6. ELSEIF an input number is invalid(ie decimal or less than 0),
  7. display an error message,
  8. ELSE
  9.    WHILE both number of candies > 11 and number of pidgeys > 0,
  10.       subtract 11 from number of candies,
  11.       subtract 1 from number of pidgeys,
  12.       add 1 to the output,(Experience points)
  13.    ENDWHILE
  14.    for each current exp point,add 24 seconds to the timer,
  15.    show timer,
  16.    divide timer by 1800,(half an hours' worth of seconds)
  17.    round timer up,(to the nearest whole number)
  18.    this is the number of lucky eggs required,
  19.    show number of lucky eggs required,
  20.    multiply Experience points by 500,then by 2 if a lucky egg is used,
  21.    show Experience points,
  22.    show remaining number of candies and/or number of pidgeys,
  23. ENDIF
  24. END*/
  25.  
  26. #include <stdio.h>
  27. #include <math.h>
  28.  
  29. int IsInteger (float PossibleInteger){ /*a short function to determine non-integer values for error checking*/
  30.    
  31.    int a, b;
  32.      
  33.    a = ceil(PossibleInteger);/*always rounds up to the nearest integer*/
  34.    b = floor(PossibleInteger);/*always rounds down to the nearest integer*/
  35.  
  36.    if (b == a){/*the only case when a==b is when the input is an integer*/
  37.       
  38.       return 1;
  39.    }
  40.    else{
  41.       
  42.       return 0;
  43.    }
  44. }
  45.  
  46. int main ( void ){
  47.  
  48.    int EXP = 0;
  49.    int EggConst = 2;/*default value assumes egg is used, and applies its multiplier of 2*/
  50.    float Pokemon = 0;
  51.    float Candies = 0;
  52.    float Time = 0;
  53.    char Egg = '\0';
  54.  
  55.    scanf("%f %f %c", &Pokemon, &Candies, &Egg);/*takes 2 seperate numbers as inputs, followed by an optional letter to indicate if a lucky egg is used*/
  56.    
  57.    if ((Candies == 0) || (Pokemon == 0)) {/*assumes 0 is no input, as opposed to an input of 0, also prevents words as inputs (incompatible variable)*/
  58.    
  59.       printf("Err: Missing input(s)");
  60.    }
  61.    
  62.    else if ((Candies < 0) || (Pokemon < 0)) {/*checks for negative values*/
  63.  
  64.       printf("Err: Invalid input, negative value(s)");
  65.    }
  66.    
  67.    else if ((IsInteger(Candies) == 0) || (IsInteger(Pokemon) == 0)) {/*checks for integer inputs*/
  68.  
  69.       printf("Err: Invalid input, non-integer value(s)");
  70.    }
  71.  
  72.    else if (Candies < 12) {/*checks intial candy is more than 11*/
  73.    
  74.       printf("Err: Insufficient candy");
  75.    }
  76.    
  77.    else if ((Egg != '\0') && (Egg != 'N') && (Egg != 'n') && (Egg != 'Y') && (Egg != 'y')) {/*checks for valid letters, also prevents numerical inputs*/
  78.       
  79.       printf("Err: Invalid inputs");
  80.    }
  81.    
  82.    else {
  83.       
  84.       while ((Candies > 11) && (Pokemon > 0)){/*candy evolve cost is 12, but one is returned before the next evolve can happen, thus 11*/
  85.    
  86.          Candies = Candies - 11;
  87.          Pokemon--;
  88.          EXP++;
  89.       }
  90.       
  91.       Time = 0.4 * EXP;/*24 seconds is the value I arrived at through testing (which is 0.4 mins)*/
  92.       printf("%.1f mins: Approximate time in minutes to evolve %d Pidgeys \n", Time, EXP);
  93.      
  94.       if ((Egg == 'N') || (Egg == 'n')){/*if no lucky egg is used, change the multiplier and do not show the 'recommended' egg number*/
  95.          
  96.          EggConst = 1;
  97.          printf("No lucky egg used,");
  98.       }
  99.      
  100.       else {/*if a lucky egg is to be used, display number of lucky eggs required for the number of evolutions*/
  101.          
  102.          Time = Time/1800;
  103.          printf("%.0f: Recommended number of lucky eggs to be used\n", ceil(Time));
  104.       }
  105.      
  106.       EXP = EXP * 500 * EggConst;/*base 500 EXP for evolving any pokemon, multiplied by the 2x bonus from the lucky egg*/
  107.       printf("%d EXP earned from evolving %d Pidgeys \n", EXP, (EXP/(500*EggConst)));
  108.    }
  109.    
  110. }