<mosaic.cnfolio.com>
PROGRAM
  1. /*  Declare integer variables named pokemonCount, candies
  2. Get pokemonCount and candies input from user
  3. Initialising XP, cost and newPokemon
  4. if (incorrect input)
  5. {
  6.    inform user and dont compute XP
  7. }
  8. else
  9.  
  10.    while(there is a possibility that at least one pokemon can be evolved)
  11.    
  12.       if(candies < cost)
  13.       {
  14.          transfer pokemon in return for candy
  15.       }
  16.       else if(pokemonCount > 0)
  17.       {
  18.          if(you do not have an evolved pokemon)
  19.          {
  20.             add 2000 to XP   
  21.          }
  22.          else
  23.          {
  24.             add 1000 to XP
  25.          }
  26.          reduce pokemon by one
  27.          reduce candies by cost
  28.          add one candy for evolving 
  29.       }
  30.    }
  31.    print the XP earned
  32. }
  33. */
  34.  
  35.  
  36.  
  37. #include <stdio.h>
  38. #include <stdbool.h>
  39. int main(void)
  40. {
  41.  
  42.    
  43.    //reading values of pokemonCount and candies
  44.    int pokemonCount, candies;
  45.         int XP = 0; //XP starts from 0
  46.    bool newPokemon = true; //ie you do not have a Pidgeotto
  47.    int cost = 12; //the candy cost for evolving a Pidgey
  48.    
  49.    
  50.    printf("Enter the number of Pidgeys and Candies:\n");
  51.    scanf("%d %d", &pokemonCount, &candies);
  52.    
  53.    
  54.    //making backup of values to be used in printf later on
  55.    int pCount = pokemonCount;
  56.    int cCount = candies;
  57.    
  58.    
  59.    
  60.    if(pokemonCount <= 0) //checking for invalid input for pokemonCount
  61.    {
  62.       printf("Invalid number of Pidgeys\n");
  63.    }
  64.    
  65.    else if(candies < 12) //checking for invalid input for candies
  66.    {
  67.       printf("Invalid number of candies\n");
  68.    }
  69.    
  70.    else
  71.    
  72.    {   
  73.     while (pokemonCount > 0 && pokemonCount + candies >= cost) //this loop runs till either we run out of pidgeys or till candies can never be more than cost
  74.       {
  75.          if (candies < cost) //if number of candies are less than evolution cost then transfer one of the Pidgeys you already have and get a candy in return
  76.          {
  77.             pokemonCount--;
  78.             candies++;
  79.          }
  80.          else if (pokemonCount > 0)
  81.          {
  82.             if (newPokemon)
  83.             { //ie if the player has zero Pidgeottos
  84.                XP = XP + 2000; //you get +1000 bonus XP
  85.                newPokemon = false; //you can no longer get this bonus since you now have a Pidgeotto
  86.             }
  87.             else
  88.             {
  89.                XP = XP + 1000; //XP earned when evolving a pokemon while a golden egg is in use
  90.             }
  91.             pokemonCount--; //one pidgey evolved
  92.             candies = candies - cost; //cost candies used for evolving
  93.             candies++; //you get a bonus candy when you evolve a Pokemon
  94.          }
  95.       }
  96.       
  97.       printf("The max XP that can be earned by evolving %d Pidgeys with %d Candies\nwhile using a lucky egg is: %d\n\n",pCount,cCount,XP);
  98.    } 
  99.    
  100.   }