<mosaic.cnfolio.com>
PROGRAM
  1. /* Pseudo Code:
  2. START
  3.  
  4.    Display how to input the number of Candies, Pokemon, and Pokemon Name
  5.    Read the inputs; number of Candies, number of Pokemon, and Pokemon Name
  6.    
  7.    Convert first letter of Pokemon Name to uppercase
  8.    
  9.    WHILE loop < 70
  10.       IF ( "Name of Pokemon" matches "Pokemon number [loop]" )
  11.          THEN
  12.             Pokemon number = loop
  13.             validpokemon = 1
  14.       END IF
  15.      
  16.       increase loop by 1
  17.    END WHILE
  18.    
  19.    IF (    number of Candies is a positive number AND Pokemon is a positive number AND Tier is a positive number
  20.         AND number of Candies is a not decimal AND Pokemon is a not decimal AND Tier is a not decimal
  21.         AND validpokemon = 1
  22.       )   
  23.    
  24.       THEN
  25.          WHILE number of Candies >= Required Candies for Pokemon number and Pokemon >= 1
  26.             THEN
  27.                Pokemon = Pokemon - 1
  28.                number of Candies = number of Candies - (Required Candies for Pokemon number - 1) (I do 1 minus the required to evolve a pokemon as evolving a pokemon gains you 1 candy)
  29.                Evolutions = Evolutions + 1
  30.          END WHILE
  31.    
  32.          XP = Evolutions * 1000
  33.       Timetaken = 28 * Evolutions (The fastest it is possible to evolve a pokemon because of the animations and interface is approximatly 28 seconds)
  34.          Timeremaining = 1800 - Timetaken (The lucky egg lasts 30 mins which is 1800 seconds)
  35.    
  36.          IF Timeremaining < 0
  37.             THEN
  38.                Eggsrequired = Timetaken / 1800
  39.                Round eggsrequired up
  40.                Timeremaining = 0
  41.          
  42.          END IF
  43.    
  44.          Display  XP, evolutions, remaining Pokemon, remaining Candies, evolutions, time taken, lucky egg time remaining, eggs required.
  45.      
  46.      
  47.       ELSE
  48.          IF number of Candies is not a positive number OR Pokemon is not a positive number
  49.             THEN
  50.                Display an error message
  51.          END IF
  52.  
  53.          IF number of Candies is a decimal OR Pokemon is a decimal
  54.             THEN
  55.                Display an error message
  56.          END IF
  57.          
  58.          IF validpokemon == 0
  59.             THEN
  60.                Display an error message
  61.          END IF
  62.          
  63.    END IF
  64.  
  65. END
  66. */
  67.  
  68. #include <stdio.h>
  69. #include <math.h>
  70. #include <string.h>
  71. #include <ctype.h>
  72.  
  73. int main( void )
  74. {
  75.    
  76.    float candies = 0, pokemon = 0; /* I am using floats for the inputs so that scanf acts predictably when invalid values are entered and I can easily detect these invalid values */
  77.    float eggsrequired = 1, timetaken = 0; /* Both these variables need to be floats to deal with fractional times and round correctly */
  78.    int evolutions = 0, luckyeggtimeremaining = 0, XP = 0, pokenum = 0, loop = 0, validpokemon = 0; /* These variables can be intergers as they are used after the inputs are checked */
  79.    char inputpokemon[16] = {"Pidgey"}; /* The input array is initated as Pidgey so no name input defaults to Pidgey, as per the requirements */
  80.    char pokemonname[70][16]={"Caterpie","Weedle","Pidgey","Eevee","Bulbasaur","Charmander","Squirtle","Rattata","Nidoran","Oddish","Poliwag","Abra","Machop","Bellsprout","Geodude","Gastly","Dratini","Metapod","Kakuna","Pidgeotto","Spearow","Ekans","Pikachu","Sandshrew","Clefairy","Vulpix","Jigglypuff","Zubat","Paras","Venonat","Diglett","Meowth","Psyduck","Mankey","Growlithe","Tentacool","Ponyta","Slowpoke","Magnemite","Doduo","Seel","Grimer","Shellder","Drowzee","Krabby","Voltorb","Exeggcute","Cubone","Koffing","Rhyhorn","Horsea","Goldeen","Staryu","Omanyte","Kabuto","Ivysaur","Charmeleon","Wartortle","Nidorina","Nidorino","Gloom","Poliwhirl","Kadabra","Machoke","Weepinbell","Graveler","Haunter","Dragonair","Magikarp","\0"};
  81.    /* The above array contains all the names of the pokemon that can be evolved (ie not final form pokemon) */
  82.    int requiredcandies[70]={12,12,12,25,25,25,25,25,25,25,25,25,25,25,25,25,25,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,100,100,100,100,100,100,100,100,100,100,100,100,100,400};
  83.    /* The above array contains the number of candies required to evolve the different tiers of pokemon, the positions line up with the name array */
  84.    
  85.    printf( "\nPlease input the number of pokemon, the number of candies,\nand optionally the name of the pokemon, separated by a space" );
  86.    /* Tell the user how to input the values correctly */
  87.    
  88.    scanf( "%f %f %s", &pokemon, &candies, &inputpokemon);
  89.    
  90.    inputpokemon[0]=toupper(inputpokemon[0]); /* In the name array, the first letter is always uppercase so this converts the first letter to uppercase */
  91.    
  92.    for(loop=0;loop < 70; loop++){
  93.       if(strcmp(inputpokemon,pokemonname[loop])==0){
  94.          pokenum = loop; /* The names of the pokemon and the amount of candies they require to evolve are placed in he same position in their respective arrays */
  95.          validpokemon = 1;
  96.       }
  97.    }
  98.  
  99.    
  100.    if( candies > 0 && pokemon > 0 && floor(candies) == candies && floor(pokemon) == pokemon && candies >= requiredcandies[pokenum] && validpokemon == 1){
  101.    /* The above if statement will return true for all valid inputs in any combination */
  102.             
  103.          while( candies >= requiredcandies[pokenum] && pokemon >= 1 ){
  104.             pokemon = pokemon - 1;
  105.             candies = candies - (requiredcandies[pokenum] - 1 );
  106.             evolutions++;    
  107.          }
  108.    
  109.          XP = evolutions * 1000;
  110.          timetaken = 28 * evolutions;
  111.          luckyeggtimeremaining = 1800 - timetaken;
  112.    
  113.          if( luckyeggtimeremaining < 0 ){
  114.             eggsrequired = ceil( timetaken / 1800 );
  115.             luckyeggtimeremaining = 0;
  116.         }
  117.      
  118.          printf("\n\nXP earnt = %d, from %d Evolution(s) of %s\nRemaining %s(s) = %.0f, remaining Candies = %.0f\nThe %d Evolution(s) took approximately %.0f seconds,\nLeaving %d seconds remaining of the intial lucky egg bonus\nYou require %.0f lucky egg(s)", XP, evolutions, inputpokemon, inputpokemon, pokemon, candies, evolutions,timetaken,luckyeggtimeremaining, eggsrequired);
  119.    }
  120.    
  121.    else { /* the following code will print specific error messages for invalid inputs */
  122.        if( candies <= 0 || pokemon <= 0){
  123.             printf( "\n\nPlease only enter positive numbers for all inputs" );
  124.          } 
  125.          if( floor(candies) != candies || floor(pokemon) != pokemon){
  126.             printf( "\n\nPlease only enter whole numbers for all inputs" );
  127.          }
  128.          if( candies < requiredcandies[pokenum] ){
  129.             printf( "\n\nYou do not have enough candies to evolve your pokemon" );
  130.          }
  131.          if( validpokemon == 0 ){
  132.             printf( "\n\nPlease enter the valid name of a Pokemon that can be evolved" );
  133.          }
  134.    }
  135. }