<mosaic.cnfolio.com>
PROGRAM
  1. /*START
  2. Initialize all the variables to 0
  3. Initialize pokemon type for pidgey (1)
  4.   Obtain 3 inputs
  5.      IF 3 correct inputs are obtained
  6.         IF inputs are negative
  7.            IF pidgey, cost is 12
  8.               ELSE IF ratttata cost is 25
  9.               ELSE IF zubat cost is 50
  10.            IF pokemon type isnt set
  11.               WHILE END is 0 continue loop
  12.                  IF you have 1 pokemon
  13.                     IF you have enough candies
  14.                        EVOLVE 1 pokemon
  15.                        +1000 XP
  16.                        -1 pidgey
  17.                        -12 candies
  18.                        +1 candy for evolve
  19.                        +1 candy for evolved pokemon transfer
  20.                     ELSE we need to transfer pokemon
  21.                        IF the sum of candies and pokemon ( - 1 pokemon ) = the cost of evolve
  22.                           TRANSFER required pokemon
  23.                           Initialize transfer number as evolve cost - candies
  24.                           Take away the number of pokemon required for transfer
  25.                           Add that number to the total amount of candies
  26.                        ELSE not enough candies or pokemon
  27.                  ELSE not enough pokemon
  28.               END WHILE when end is 1
  29.               Display total xp
  30.            ELSE display invalid pokemon type
  31.         ELSE display negative numbers not accepted
  32.      ELSE Ask for number the of pokemon annd candies available, also display different pokemon types accepted
  33. END */
  34.  
  35.  
  36. #include <stdio.h>
  37. int main (void)
  38. {
  39.     int pokemon=0;
  40.     int candies=0;
  41.     int evolve_cost=0;
  42.     int XP=0;
  43.     int end=0;        /* End is the loop exit in boolean. */
  44.     int num_of_matched_inputs=0;  /* Scanf output, telling how many inputs were sucessfully matched to variables. */
  45.     int pokemon_to_transfer=0;      /* Number of pokemon needed to transfer to have 12 candies. */
  46.     int pokemon_type=1;     /* Pidgey is 1, rattata is 2, zubat is 3. */
  47.    
  48.     /* Scan input for number of pokemon and candies.*/
  49.     num_of_matched_inputs = scanf( "%d %d %d", &pokemon, &candies, &pokemon_type);
  50.     /* Make sure scan matches three input.*/
  51.     if (num_of_matched_inputs == 2 || num_of_matched_inputs == 3)
  52.     {
  53.         /* Make sure numbers are positive. */
  54.         if ( pokemon >= 0  && candies >=0  )
  55.         {
  56.           /* Set evolve cost depending on pokemon type. */
  57.             if (pokemon_type == 1)
  58.             {
  59.                 evolve_cost = 12;
  60.             }
  61.             else if (pokemon_type == 2)
  62.             {
  63.                 evolve_cost = 25;
  64.             }
  65.             else if (pokemon_type == 3)
  66.             {
  67.                 evolve_cost = 50;
  68.             }
  69.             /* Only continue if cost has been set. */
  70.             if (evolve_cost > 0)
  71.             {
  72.                 /* Start loop to evolve pokemon. */
  73.                 do
  74.                 {
  75.                     /* Check we have at least one pokemon to evolve. */
  76.                     if( pokemon >= 1)
  77.                     {
  78.                         /* Check we have the right ammount of candies to pay for evolve. */
  79.                         if ( candies >= evolve_cost )
  80.                         {
  81.                             /* Start EVOLVE. */
  82.                            
  83.                             /* Use right ammount of candies. */
  84.                             candies = candies - evolve_cost;
  85.                             /* Evolve one pokemon. */
  86.                             pokemon--;
  87.                             /*  Gain 1000xp. */
  88.                             XP = XP + 1000;
  89.                             /* Get 1 candy back from evolve. */
  90.                             candies++;
  91.                             /* Transfer resulting evolved pokemon for 1 candy. */
  92.                             candies ++;
  93.                         }
  94.                         else
  95.                         {
  96.                             /* We need at least the evolve cost of combined candies and pokemon + 1 extra pokemon to evolve. */
  97.                             if ( candies + (pokemon-1) >= evolve_cost )
  98.                             {
  99.                                 /* Transfer the number of pokemon needed to have the right amount of candies in total. */
  100.                                 pokemon_to_transfer = evolve_cost-candies;
  101.                                 pokemon = pokemon - pokemon_to_transfer;
  102.                                 candies = candies + pokemon_to_transfer;
  103.                             }
  104.                             else
  105.                             {
  106.                                 /* Not enough candies or pokemon to continue. */
  107.                                 end = 1;
  108.                             }
  109.                         }
  110.                     }
  111.                     else
  112.                     {
  113.                         /* Not enough pokemon to continue. */
  114.                         end = 1;
  115.                     }
  116.                 }
  117.                 /* Continue looping while end boolean is false / 0. */
  118.                 while (end == 0);
  119.                
  120.                 /* Print the max xp score.*/
  121.                 printf("you could get %d xp!", XP);
  122.             }
  123.             else
  124.             {
  125.                 /* Evolve cost not set because pokemon type was wrong. */
  126.                 printf( "%d is not a recognised pokemon type.", pokemon_type);
  127.             }
  128.         }
  129.        
  130.         else
  131.         {
  132.           /* Pokemon number or candy number was negative. */
  133.             printf( "You can't enter negative numbers.");
  134.         }
  135.     }
  136.     else
  137.     {
  138.         /* Number of recognised input was incorrect. */
  139.         printf( "Please enter the number of pokemon, candies and the pokemon type number: pidgey is 1, rattata is 2, zubat is 3 \n" );
  140.     }
  141. }