<mosaic.cnfolio.com>
PROGRAM
  1. /** A program that calculates the maximum amount of experience points (XP) that a
  2. Poke&#769;mon Go player can earn by using a Lucky Egg bonus timer and evolving Pidgey pokemons.
  3.  
  4. Author:
  5.  
  6. Pseudocode for the Implementation of the Program.
  7.  
  8. initialize the total evolutions to 0
  9. display pokemons for selection
  10. read selection
  11. read input for candy and number of pidgeys
  12.  
  13. while number of pokemons is greater than 0 or candies plus the number of Pokemons is greater than the required number
  14. increment pokemon by one;
  15. increment candies by one;
  16. increment possible evolutions by one;
  17. set the total evolutions to the possible evolutions
  18. otherwise
  19. break
  20.  
  21. print results;
  22.  
  23. */
  24.  
  25. /** SAMPLE OUTPUT
  26.  
  27.  
  28. *******************************Pokemon Go XP CALCULATOR*******************************************
  29.  
  30. Please Select a pokemon:
  31. 1. Pidgie
  32. 2. Rattata
  33. 3. Zubat
  34. 1
  35. You Selected A Pidgy
  36. Enter the number of Pidgy pokemons and  pidgey candy in Your Inventory: 600 600
  37.  
  38. *************************************RESULTS!!!****************************************************
  39.  
  40.  
  41. Evolutions: 99.000000
  42. The Maximum XP Earned IS 99000.000000 In  TIME: 50 Minutes
  43.  
  44.  
  45. RESULT: You should use 1 Lucky Egg(s)
  46.  
  47.  
  48. *************************************END OF RESULTS!!!*************************************
  49. Process returned 94 (0x5E)   execution time : 5.892 s
  50. Press any key to continue.
  51.  
  52.  
  53.  
  54.  
  55. */
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <math.h>
  60. #include <ctype.h>
  61.  
  62. int MIN(int a, int b)
  63. {
  64.    if (a < b)
  65.    {
  66.       return a;
  67.    }
  68.    else
  69.    {
  70.       return b;
  71.    }
  72. }
  73. //First Declare the total evolution as a global variable
  74. double totalEvoCount = 0;
  75.  
  76. void getResults(int amountPokemons, int candy, int req) {
  77.  
  78.    //Find the number of evolutions for candy.
  79.    int numEvo = (int)(candy / req);
  80.    //The number of possible evolutions are now the lowest of the evolution of candy and the number of pidgies
  81.    int numPossibleEvo = MIN(amountPokemons, numEvo);
  82.    //Find the number of candies
  83.    candy = candy - (numPossibleEvo * req) + numPossibleEvo;
  84.    //Find the number of pokemon evolution to work with by subtracting the number of possible
  85.    //Evolutions
  86.    amountPokemons = amountPokemons - numPossibleEvo;
  87.  
  88.  
  89.    //Algorithm to find the number of evolutions
  90.    //enclosed in an infinite loop that only breaks when either the amount is 0 or the number of candies and pokemons is greater than the
  91.    //Required amount plus one
  92.    do {
  93.  
  94.       if ((candy + amountPokemons) < (req + 1) || amountPokemons <= 0)
  95.          break;
  96.  
  97.       while (candy < req) {
  98.  
  99.          amountPokemons--;
  100.          candy++;
  101.       }
  102.  
  103.       //Decrement the number of pokemons towards zero
  104.       amountPokemons--;
  105.       candy = candy - req + 1;
  106.       numPossibleEvo++;
  107.  
  108.    } while (1);
  109.  
  110.    totalEvoCount = totalEvoCount + numPossibleEvo;
  111.  
  112.  
  113.    printf("\n*************************************RESULTS!!!****************************************************\n");
  114.    printf("\n\nEvolutions: %f\n", totalEvoCount);
  115.    printf("The Maximum XP Earned IS %f In  TIME: %.0f Minutes \n\n", totalEvoCount * 1000, totalEvoCount / 2);
  116.  
  117.    //CHECK IF THE TOTAL EVOLUTION HAS IS GREATER THAN 60
  118.  
  119.    if (totalEvoCount < 60) {
  120.       double totalTime = fabs(30 - 0.5*totalEvoCount);
  121.  
  122.       printf("\nRESULT: Do NOT activate your lucky egg until you have found more Pokemons\n or else you will waste about %.1f minutes of your Lucky Egg!", totalTime);
  123.    }
  124.    else {
  125.       printf("\nRESULT: You should use %.0f Lucky Egg(s)", floor(totalEvoCount / 60)); //ASSIGN THE NUMBER OF LUCKY EGGS
  126.  
  127.    }
  128.    printf("\n\n\n*************************************END OF RESULTS!!!*************************************");
  129.  
  130.  
  131. }
  132.  
  133.  
  134. int main()
  135. {
  136.    // - Read the amount of Pidgeys and Candies from the User.
  137.    printf("\n*******************************Pokemon Go XP CALCULATOR*******************************************\n\n");
  138.    printf("Please Select a pokemon: \n");
  139.    printf("\t1. Pidgie\n \t2. Rattata\n \t3. Zubat\n");
  140.    int choice;
  141.    scanf("%d", &choice);
  142.    if (choice<1 || choice > 3)
  143.    {
  144.       printf("\"%d\" is not a valid integer, try again.\n", choice);
  145.       return -1;
  146.    }
  147.    //Declare values for candy and Pockemons
  148.    int candy;
  149.    int pokemons;
  150.  
  151.    switch (choice) {
  152.    case 1:
  153.       printf("You Selected A Pidgy");//12
  154.       printf("\nEnter the number of Pidgy pokemons and  pidgey candy in Your Inventory: ");
  155.       scanf("%d %d", &pokemons, &candy);
  156.       getResults(pokemons, candy, 12);
  157.       break;
  158.    case 2:
  159.       printf("You Selected A Rattata ");//25
  160.       printf("\nEnter the number of Rattata pokemons and  rattata candy in Your Inventory: ");
  161.       scanf("%d %d", &pokemons, &candy);
  162.       getResults(pokemons, candy, 25);
  163.       break;
  164.    case 3:
  165.       printf("Choice Was %d a Zubat", choice);//50
  166.       printf("You Selected A Zubat");//25
  167.       printf("\nEnter the number of Zubat pokemons and  Zubat candy in Your Inventory: ");
  168.       scanf("%d %d", &pokemons, &candy);
  169.       getResults(pokemons, candy, 50);
  170.       break;
  171.    default:
  172.       printf("Please pick a Valid Choice");
  173.    }
  174. }