<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3.    get the number of pidgeys
4.    get the number of candies in the inventory
5.    OPTIONAL get the pokedex_number of the pokemon you will be using
6.    IF the pokedex_number is 10, 13, 16, or 0
7.       THEN the EvoCandy is 12
8.
9.    ELSE, IF the pokedex_number is 1, 4, 7, 19, 29, 32, 43, 60, 66, 69, 74, 92, 133, or 147
10.       THEN the EvoCandy is 25
11.
12.    ELSE, IF the pokedex_number is 21, 23, 27, 35, 39, 41, 46, 48, 50, 52, 54, 56, 58, 72, 77, 79, 81, 90, 96, 98, 100, 102, 104, 109, 111, 116, 118, 120, 138, 88, or 140
13.       THEN the EvoCandy is 50
14.
15.    ELSE, IF the pokedex_number is 129
16.       THEN the EvoCandy is 400
17.
18.    ELSE, If the pokedex_number is greater than 151
19.       THEN print "Only the kanto Pokedex is available at the moment."
20.
21.    ELSE
22.       THEN print "That pokedex number is not recognised, but from a pidgey "
23.       The EvoCandy is 12
24.    ENDIF
25.
26.    IF the number of pidgeys in not a whole number
27.       THEN print"please enter an integer for pidgeys"
28.
29.    ELSE IF the number of candies is not a whole number
30.       THEN print "please enter an integer for candies
31.
32.    ELSE add the number of pidgeys to the number of candies
33.       WHILE the new number of candies is not less than the EvoCandy, AND the number of pidgeys is more than zero,
34.          add 500 to the XP
35.          take the EvoCandy from the number of candies
36.          take 1 from the number of pidgeys
37.       END WHILE
38.
39.       the Lucky egg XP is two time the XP
40.       print "you will get "
41.       print the value of XP
42.       print "XP normally, and "
43.       print the value of the Lucky Egg XP
44.       print "XP with an egg active."
45.
46.       IF the number of evolutions is greater than 60
47.          THEN "limit" is the number of evolutions divided by 60
48.          print "However, this may be difficult to do with only one lucky egg. You might have to use "
49.          print limit
51.       END IF
52.    END IF
53. END
54. */
55.
56. #include <stdio.h>
57. #include <string.h>
58. #include <stdlib.h>
59.
60. int round(double x);
61. double pidgey_input=0,candy_input=0,pokedex_number=0,counter=0;
62. int pidgey_rounded=0,candy_rounded=0,xp=0,LExp=0,evocandy=0;
63.
64. int main( void ){
65.    scanf("%lf %lf %lf", &pidgey_input, &candy_input, &pokedex_number);
66.    if(pokedex_number == 10 || pokedex_number == 13 || pokedex_number==16||pokedex_number==0) /*this represents the pokedex number for all of the lowest evolution of each pokemon in the game, allowing the user to choose which pokemon they want to use for gaining xp from a lucky egg*/
67.       evocandy = 12;
68.
69.    else if(pokedex_number==1||pokedex_number==4||pokedex_number==7||pokedex_number==19||pokedex_number==29||pokedex_number==32||pokedex_number==43||pokedex_number==60||pokedex_number==66||pokedex_number==69||pokedex_number==74||pokedex_number==92||pokedex_number==133||pokedex_number==147)
70.       evocandy=25;
71.
72.    else if(pokedex_number==21||pokedex_number==23||pokedex_number==27||pokedex_number==35||pokedex_number==39||pokedex_number==41||pokedex_number==46||pokedex_number==48||pokedex_number==50||pokedex_number==52||pokedex_number==54||pokedex_number==56||pokedex_number==58||pokedex_number==72||pokedex_number==77||pokedex_number==79||pokedex_number==81||pokedex_number==84||pokedex_number==86||pokedex_number==90||pokedex_number==96||pokedex_number==98||pokedex_number==100||pokedex_number==102||pokedex_number==104||pokedex_number==109||pokedex_number==111||pokedex_number==116||pokedex_number==118||pokedex_number==120||pokedex_number==138||pokedex_number==88||pokedex_number==140)
73.       evocandy=50;
74.
75.    else if(pokedex_number==129)
76.       evocandy=400;
77.
78.    else if (pokedex_number>151){
79.       printf("Only the kanto pokedex is available at the moment.");
80.         return(0);
81.       }
82.    else {
83.    printf("Pokedex number not recognised, but from a pidgey "); /*this could be an error message instead, but I think that showing a number for XP is more helpful.*/
84.    evocandy=12;
85.    }
86.
87.
88.    pidgey_rounded= round(pidgey_input);
89.    candy_rounded=round(candy_input);   /*this generates the error message that is part of the specification. There is one error for an incorrect value of pidgeys and one for candies.*/
90.    if((pidgey_rounded!=pidgey_input) || (pidgey_input == 0)){
91.    printf("please enter an integer for pidgeys");
92.    }
93.    else if((candy_rounded!=candy_input) || (candy_input==0)){
94.    printf("please enter an integer for candies");
95.    }
96.    else{
97.       candy_rounded=candy_rounded + (pidgey_rounded)/* while there are more candies than are needed to evolve the pokemon AND there is at least one pidgey left, the xp value is increased by 500.*/
98.       while((candy_rounded>=evocandy)&&(pidgey_rounded>0)){
99.          candy_rounded= candy_rounded-evocandy;
100.       pidgey_rounded-=1;
101.          xp+=500;
102.       counter+=1;
103.          }
104.       LExp=xp*2;
105.       printf("You will get %d xp normally, ", xp);
106.       printf("and %d xp with an egg active. \n", LExp);
107.       if (counter>60)      /* this IF statement is used if there is a posibility of the user running out of time while evolving pokemon*/
108.          {
109.          counter=round(counter/60);
110.          printf("However, this may be difficult to do with one lucky egg. You might have to use %.lf instead.", counter);
111.          }
112.
113.       }
114.    }
115.
116.
117.
118. int round(double x){ /*This funtion rounds a float to an integer using normal maths rules; using 0.5 as the cut off point for rounding up and down*/
119.    double working=x;
120.
121.    while( working >=1)
122.    {
123.       working = working-1/*This subtracts 1 from the input number until the number is less than one, meaning only the decimal point is left.*/
124.    }
125.
126.    if(working<0.5) /*If the decimal number is greater than 0.5, the input is rounded up, otherwise the number is rounded down.*/
127.    {
128.       x=x-working;
129.    }
130.    else
131.    {
132.       x=x +1 -working;
133.    }
134.    return x;
135. }