<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE
  3.  
  4. START PROGRAM
  5.  
  6. MAIN FUNC
  7. START MAIN
  8.  
  9. INT EVOLVECOUNT = 0
  10. INT TRANSFERCOUNT = 0
  11.  
  12. PRINT 'Welcome to the Pokemon Calculator'
  13. PRINT 'Select a Pokemon:'
  14. SET pokemonList[3] TO 'Pidgey', 'Ratatta', 'Drowzee'
  15. FOR INT i < 3
  16.    PRINT pokemonList[i]
  17. END FOR
  18. INT CHOICE = 0
  19. INPUT user inputs integer to select pokemon
  20. STORE user input IN CHOICE variable
  21. IF CHOICE == 1
  22.    THEN
  23.       PRINT 'You selected Pidgey'
  24. ELSE IF CHOICE == 2
  25.    THEN
  26.       PRINT 'You selected Ratatta'
  27. ELSE IF CHOICE == 3
  28.    THEN
  29.       PRINT 'You selected Drowzee'
  30. ELSE
  31.    PRINT 'Incorrect Input, Try again! Aborting'
  32.    END
  33. END IF
  34.  
  35. PRINT 'Please enter the number of Pokemon'
  36. INT POKEMONNUMBER = 0
  37. INPUT user enters number of pokemon they have
  38. STORE user input IN POKEMONNUMBER
  39. IF POKEMONNUMBER > 9999
  40.    THEN
  41.       PRINT ERROR 'Input exceeds program limit'
  42.       END
  43. END IF
  44.    
  45. PRINT 'Please enter the number of Pokemon Candy'
  46. INT POKEMONCANDY = 0
  47. INPUT user inputs number of pokemon candy
  48. STORE user input IN POKEMONCANDY
  49. IF POKEMONCANDY > 99999
  50.    THEN
  51.       PRINT ERROR 'Input exceeds program limit'
  52.       END
  53. END IF
  54.    
  55. INT REQUIREDCANDIES = 0   
  56. IF CHOICE == 1
  57.    THEN
  58.       REQUIREDCADIES = 12
  59.       CALL FUNC EVOLVEPOKEMON
  60.       CALL FUNC RESULTS
  61. ELSE IF == 2
  62.    THEN
  63.       REQUIREDCANDIES = 25
  64.       CALL FUNC EVOLVEPOKEMON
  65.       CALL FUNC RESULTS
  66. ELSE IF == 3
  67.    THEN
  68.       REQUIREDCANDIES = 50
  69.       CALL FUNC EVOLVEPOKEMON
  70.       CALL FUNC RESULTS
  71. END IF   
  72. END MAIN FUNC
  73.    
  74. EVOLVEPOKEMON FUNC
  75. START EVOLVEPOKEMON
  76.  
  77. INT CANEVOLVE = 1
  78. WHILE CANEVOLVE = 1
  79.    IF POKEMONCANDY / REQUIREDCANDIES = 0 OR POKEMONNUMBER = 0
  80.       THEN
  81.          BREAK
  82.    ELSE
  83.       POKEMONNUMBER - 1
  84.       POKEMONCANDY = POKEMONCANDY - REQUIREDCANDIES
  85.       POKEMONCANDY + 1
  86.       EVOLVECOUNT + 1
  87.       IF POKEMONNUMBER = 0
  88.          THEN
  89.             BREAK
  90.       END IF
  91.    END IF
  92. END WHILE
  93.  
  94. INT CANTRANSFER = 1
  95. WHILE CANTRANSFER = 1
  96.    IF POKEMONCANDY + POKEMONNUMBER < REQUIREDCANDIES + 1 OR POKEMONNUMBER = 0
  97.       THEN
  98.          BREAK
  99.       ELSE
  100.          WHILE POKEMONCANDY < REQUIREDCANDIES
  101.             TRANSFERCOUNT + 1
  102.             POKEMONNUMBER - 1
  103.             POKEMONCANDY + 1
  104.             IF POKEMONNUMBER = 0
  105.                THEN
  106.                   BREAK
  107.             END IF
  108.          END WHILE
  109.    POKEMONNUMBER - 1
  110.    POKEMONCANDY = POKEMONCANDY - REQUIREDCANDIES
  111.    POKEMONCANDY + 1
  112.    EVOLVECOUNT + 1
  113.    IF POKEMONNUMBER = 0
  114.       THEN
  115.          BREAK
  116.    END IF
  117.  
  118. END EVOLVEPOKEMON FUNC
  119.            
  120. RESULTS FUNC
  121. START RESULTS
  122.  
  123. DOUBLE EVOLVETIME = 12
  124. DOUBLE LUCKYEGGUSE = EVOLVECOUNT * EVOLVETIME / 60 / 30
  125. INT XP = EVOLVECOUNT * 1000
  126. DOUBLE TOTALEVOLVETIME = EVOLVECOUNT * EVOLVETIME / 60
  127.  
  128. IF LUCKYEGGUSE MORE THAN OR = 1
  129.    THEN
  130.       PRINT 'Use: LUCKYEGGUSE Lucky Eggs'
  131.       PRINT 'Transfer TRANSFERCOUNT Pokemon'
  132.       PRINT 'Evolve EVOLVECOUNT Pokemon'
  133.       PRINT 'Gaining XP * 2 xp'
  134.       PRINT 'Total evolve time: TOTALEVOLVETIME minutes'
  135.    ELSE
  136.       PRINT 'Do not use a Lucky Egg, Catch some more Pokemon'
  137.       PRINT 'Transfer: TRANSFERCOUNT Pokemon'
  138.       PRINT 'Gaining XP xp'
  139.       PRINT 'With a Lucky Egg: XP * 2 xp'
  140.       PRINT 'Total evolve time: TOTALEVOLVETIME minutes'
  141. ENDIF
  142.  
  143. END RESULTS FUNC
  144.  
  145. END PROGRAM
  146.    
  147. PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE ---- PSUEDO CODE
  148. */
  149.  
  150. #include <stdio.h>
  151. #include <math.h>
  152.  
  153. /* declaring functions */
  154. /* The two functions below utilise pointer variables so that I can pass and return multiple values to a fucntion */
  155. void evolvePokemon(int *rc, int *pn, int *pc, int *ec, int *tc);
  156. void results(int *pn, int *pc, int *ec, int *tc);
  157.  
  158. int main (void)
  159. {
  160.    /* Declaring main variables, semantically named */
  161.    int pokemonNumber = 0;
  162.    int pokemonCandies = 0;
  163.    int requiredCandies = 0;
  164.    int evolutionsCompleted = 0;
  165.    int transfersCompleted = 0;
  166.    
  167.    printf("Welcome to the Pokemon Calculator\nDesigned and Programmed by Liam Taylor");
  168.    printf("\nSelect a Pokemon:");
  169.    /* a character array to store 3 strings, also the 3 pokemon compatible with the program */
  170.    char *pokemonList[3];
  171.    /* Adding the strings to the character array */
  172.    pokemonList[0] = "\n(1)Pidgey";
  173.    pokemonList[1] = "\n(2)Ratatta";
  174.    pokemonList[2] = "\n(3)Drowzee";
  175.    int i;
  176.    /* a FOR loop to print the character array to the user */
  177.    for(i = 0; i < 3; i++)
  178.    /* using int i to step through the array */
  179.       printf(pokemonList[i]);
  180.      
  181.    int choice = 0;
  182.    /* reading and storing the user's selection of pokemon */
  183.    scanf("%d", &choice);
  184.    /* if user input eqauls 1-3 this will print and select the corresponding pokemon */
  185.    if(choice == 1)
  186.       printf("\nYou selected Pidgey");
  187.    else if (choice == 2)
  188.       printf("\nYou selected Ratatta");
  189.    else if (choice == 3)
  190.       printf("\nYou selected Drowzee");
  191.    else
  192.    {
  193.    /* If the input is outside the accepted parameters, a error message is displayed and the program is exited */
  194.       printf("\n\nINCORRECT SELECTION INPUT, TRY AGAIN!\nINPUT MUST BE 1, 2 OR 3!");
  195.       exit(0);
  196.    }
  197.      
  198.    /* user now enters the number of pokemon they have and stores it in a local varialbe */
  199.    printf("\n\nPlease enter the number of the selected Pokemon you have:");
  200.    scanf("%d", &pokemonNumber);
  201.    /* input is printed to the screen */
  202.    printf(" %d", pokemonNumber);
  203.    
  204.    /* if the input exceeds 9999, an error is displayed and the program exits */
  205.    if (pokemonNumber > 9999)
  206.    {
  207.       printf("\n\nNUMBER EXCEEDS PROGRAM LIMIT\nINPUT A NUMBER UNDER 9999");
  208.       /* stops compiling */
  209.       exit(0);
  210.    }
  211.    
  212.    /* user inputs the amount of pokemon candies and is stored in a local variable */
  213.    printf("\nPlease enter the number of candies you have for the selected Pokemon:");
  214.    scanf("%d", &pokemonCandies);
  215.    printf(" %d", pokemonCandies);
  216.    
  217.    /* if the input exceeds 99999, an error is displayed and the program with exit */
  218.    if (pokemonNumber > 99999)
  219.    {
  220.       printf("\n\nNUMBER EXCEEDS PROGRAM LIMIT\nINPUT A NUMBER UNDER 99999");
  221.       /* stops compiling */
  222.       exit(0);
  223.    }
  224.    
  225.    /* Declare a switch statement using the choice variable */
  226.    switch (choice)
  227.    {
  228.       /* case statement for Pidgey */
  229.       case 1:
  230.          requiredCandies = 12;
  231.          /* calls the evolvePokemon function passing the local variables as pointers to the fucntion */
  232.          evolvePokemon(&requiredCandies, &pokemonNumber, &pokemonCandies, &evolutionsCompleted, &transfersCompleted);
  233.          /* calls the results function passing the local variables as pointers to the fucntion */
  234.          results(&pokemonNumber, &pokemonCandies, &evolutionsCompleted, &transfersCompleted);
  235.          break;
  236.          
  237.       /* case statement for Ratatta */   
  238.       case 2:
  239.          requiredCandies = 25;
  240.          evolvePokemon(&requiredCandies, &pokemonNumber, &pokemonCandies, &evolutionsCompleted, &transfersCompleted);
  241.          results(&pokemonNumber, &pokemonCandies, &evolutionsCompleted, &transfersCompleted);
  242.          break;
  243.       /* case statement for Drowzee */
  244.       case 3:
  245.          requiredCandies = 50;
  246.          evolvePokemon(&requiredCandies, &pokemonNumber, &pokemonCandies, &evolutionsCompleted, &transfersCompleted);
  247.          results(&pokemonNumber, &pokemonCandies, &evolutionsCompleted, &transfersCompleted);
  248.          break;
  249.       /* default case statement in case above error handling fails */
  250.       default:
  251.          printf("\n\nINCORRECT SELECTION INPUT, TRY AGAIN!\nINPUT MUST BE 1, 2 OR 3!");
  252.          exit(0);
  253.          break;
  254.    }
  255.    return 0;
  256. }
  257.  
  258. /* evolvePokemon function where the local variables from the MAIN function are passed to the pointers declared below */
  259. /*
  260. rc = requiredCandies
  261. pn = pokemonNumber
  262. pc = pokemonCandies
  263. ec = evolutionsCompleted
  264. tc = transfersCompleted
  265. */
  266. void evolvePokemon(int *rc, int *pn, int *pc, int *ec, int *tc)
  267.    {
  268.       /* pointer values assigned to local variables to allow greater flexibility */
  269.       int rc_temp = *rc;
  270.       int pn_temp = *pn;
  271.       int pc_temp = *pc;
  272.       int ec_temp = *ec;
  273.       int tc_temp = *tc;
  274.      
  275.       /* 'boolean' value to use in the while loop */
  276.       int canEvolve = 1;
  277.      
  278.       while(canEvolve = 1)
  279.       {
  280.          /* if there are not enough candy or pokemon, the loop breaks/stops */
  281.          if ((pc_temp / rc_temp) == 0 || pn_temp == 0)
  282.          {
  283.             break;
  284.          }
  285.          else
  286.          {
  287.             /* evolve pokemon
  288.             taking 1 away from the Pokemon number*/
  289.             pn_temp--;
  290.             /* take the required candies away from the total candies for the selected pokemon */
  291.             pc_temp -= rc_temp;
  292.             /* add 1 to the total candies for an evolution */
  293.             pc_temp++;
  294.             /* add 1 to the evolutions completed count */
  295.             ec_temp++;
  296.             /* when the number of pokemon equals 0, stop */
  297.             if(pn_temp == 0)
  298.             break;
  299.          }
  300.       }
  301.      
  302.       /* 'boolean' value to use in the while loop */
  303.       int canTransfer = 1;
  304.      
  305.       while(canTransfer = 1)
  306.       {
  307.          /* if the number of pokemon candies and pokemon is less than the minimum required for a useful transfer, break...
  308.           or if the number of pokemon = 0 stop*/
  309.          if ((pc_temp + pn_temp) < (rc_temp + 1) || pn_temp == 0)
  310.          {
  311.             break;
  312.          }
  313.          else
  314.          {
  315.             /* if the total candy is less than the required, transfer a pokemon */
  316.             while(pc_temp < rc_temp)
  317.             {
  318.                /* add one to transfers completed */
  319.                tc_temp++;
  320.                /* take 1 away from the total pokemon */
  321.                pn_temp--;
  322.                /* add 1 to the total candy */
  323.                pc_temp++;
  324.                /* when pokemon number = 0 break */
  325.                if(pn_temp == 0)
  326.                break;
  327.             }
  328.          }
  329.          /* after transferring, evolve more pokemon with newly added candies */
  330.          pn_temp--;
  331.          pc_temp -= rc_temp;
  332.          pc_temp++;
  333.          ec_temp++;
  334.          if(pn_temp == 0)
  335.             break;
  336.       }
  337.       /* assign the pointer variables to the new local varaibles */
  338.        *rc = rc_temp;
  339.        *pn = pn_temp;
  340.        *pc = pc_temp;
  341.        *ec = ec_temp;
  342.        *tc = tc_temp;
  343.        return;
  344.    }
  345.    
  346. /* results function to consolidate further calculations and output to the compiler */
  347. void results(int *pn, int *pc, int *ec, int *tc)
  348. {
  349.       /* assigned local varaibles to the pointer values */
  350.       int pn_temp = *pn;
  351.       int pc_temp = *pc;
  352.       int ec_temp = *ec;
  353.       int tc_temp = *tc;
  354.      
  355.       /* declaring the amount of time to evolve one pokemon, in this case 27 seconds */
  356.       double evolveTime = 27;
  357.       /* calculate the xp gain by multipying the number of evolutions completed by 1000 */
  358.       int xpAttained = (ec_temp * 500);
  359.       /* total evolution time calcualted by multiplying number of evoulutions completed by the evolve time (27)
  360.       and dividing by 60 to convert the value into minutes*/
  361.       double totalEvolveTime = ((ec_temp * evolveTime) / 60);
  362.       /* lucky egg use is calculated by dividing the total evolve time by 30, as to effectively
  363.       use 1 lucky egg lasts 30 minutes so if the evolve time divides into 30, lucky egg use = 1*/
  364.       int luckyEggUse = totalEvolveTime / 30;
  365.       /* if the lucky egg use is more than or equal to 1, then display results related to using a lucky egg */
  366.       if(luckyEggUse >= 1)
  367.       {
  368.          /* lucky eggs to use */
  369.          printf("\n\nYOU CAN USE %d Lucky Eggs", luckyEggUse);
  370.          /* number of transfers to make first */
  371.          printf("\nFirst, Transfer %d Pokemon/s", tc_temp);
  372.          /* Number of evolutions to make */
  373.          printf("\nWith a Lucky Egg you should evolve %d Pokemon", ec_temp);
  374.          /* display the xp gain multiplied by two due to the double XP characteristic of the lucky egg */
  375.          printf("\nGaining %dXP", xpAttained * 2);
  376.          /* display the total evolve time */
  377.          printf("\nTotal evolve time: %lf minutes", totalEvolveTime);
  378.       }
  379.       /* else no lucky egg should be used, display results */
  380.       else
  381.       {
  382.          /* warn user not to use a lucky egg */
  383.          printf("\n\nDO NOT USE any Lucky Eggs, Catch some more Pokemon!");
  384.          printf("\nFirst, Transfer %d Pokemon", tc_temp);
  385.          /* display xp gain without 2x multiplier */
  386.          printf("\nWithout a Lucky Egg you would gain %dXP", xpAttained);
  387.          /* display xp gain if lucky egg is used/wasted */
  388.          printf("\nWith a Lucky Egg, you would of gained %dXP", xpAttained * 2);
  389.          printf("\nTotal evolve time: %lf minutes", totalEvolveTime);
  390.       }   
  391. }