<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3. Declare seconds variable as an integer
4. Declare time variable as double point
5. Declare pidgey variable as an integer
6. Declare candy variable as an integer
7. Declare xp variable as an integer
8. Declare counter variable as an integer
9.
10.
11. Enter amount of Pidgeys and amount of candy in your inventory
12. Assign first input to pidgey variable and second input to candy variable
13.
14. IF Pidgy input is empty or 0
15.   THEN Show error message saying "Enter the amount of Pidgeys you wish to evolve"
16.   ENDIF
17. IF Candy input is empty or 0
18.   THEN Show error message saying "Must the amount of candy you wish to use"
19.   ENDIF
20.
21. ELSE
22.   IF Pidgy input is less than 1
23.    THEN Show error message saying "You must have at least 1 Pidgey"
24.    ENDIF
25.   IF Candy input is less than 12
26.    THEN Show error message saying "You must have at least 12 candy to evolve a Pidgey"
27.   ENDIF
28.
29. IF Pidgey is at least 1 AND candy is at least 12
30. THEN
31.   WHILE Pidgey is at least 1 AND candy is at least 12
32.    Reduce pidgey by 1
33.    Increase counter by 1
34.    Reduce candy by 11
35.    Seconds is equal to counter multiplied by 21
36.    Minutes is equal to seconds divided by 60
37.   ENDWHILE
38.
39. Show how many Pidgeys can be evolved using the counter variable
40. Equal XP to counter multiplied by 1000 and display XP
41. Display how long all evolutions will take
42. Display how many candy and non-evolved Pidgeys are still remaining
43.
44. END
45. */
46.
47. #include <stdio.h>
48.
49. int main (void)
50.
51. {
52.
53. int seconds; /*Set the seconds variable as an integer, and will represent the total seconds taken to evolve the Pidgeys*/
54. double minutes; /*Set minutes to a double as the minutes will be represented in decimal. Represents total minutes to evolve the Pidgeys*/
55. int pidgey = 0; /*Represents the amount of pidgeys inputted. Is defaulted to 0 until overwritten by a user input. Set as an integer*/
56. int candy = 0; /*Represents the amount of candies inputted. Is defaulted to 0 until overwritted by a user input. Set as an integer*/
57. int xp; /*Represents the experience points the user will receive from the evolutions. Set as an integer*/
58. int counter; /*Represents the total number of evolved Pidgeys. Set as an integer*/
59.
60.
61. scanf("%d %d", &pidgey, &candy); /*This assigns the user's inputs to the correct variables. First input goes overwrites pidgey, while the second overwrites candy*/
62.
63. if (pidgey == NULL) printf("Enter the amount of Pidgeys you wish to evolve. Input must be an integer.\n"); /*This error message is displayed if the user inputs nothing in the pidgey field, or 0*/
64. if (candy == NULL) printf("Enter the amount of candy you wish to use. Input must be an integer.\n"); /*This error message is displayed if the user entered nothing in the candy field, or 0*/
65.
66. else
67. {
68.
69. if (pidgey < 1) printf("You must own at least 1 Pidgey\n"); /*Displays a message telling the user they need at least 1 pidgey if their pidgey input was less than 1*/
70. if (candy < 12) printf("You need at least 12 pieces of candy to evolve a pidgey\n"); /*Displays a message telling the user they need more candy if
71. their candy input was less than 12*/
72. }
73.
74. if(pidgey >=1 && candy >=12) /*Checks to see if the users inputs include at least one pidgey and 12 candy. If so, the program goes ahead
75. and starts to go through the following loop. If not, the program won't go through the loop and will print the above error messages*/
76. {
77.   while ( pidgey >=1 && candy >= 12) /*Used While loop so calculation would only loop if set conditions are met. As long as pidgey is over 0
78.   and candy is 12 or over, the while loop will constantly execute until conditions are no longer met */
79.   {
80.     pidgey = pidgey - 1;
81.     counter = counter + 1; /*Counter represents the evolved pidgeys. Everytime it goes through the loop, the counter increases by 1*/
82.     candy = candy - 11; /*Used up candy is reduced each time it goes through the loop. Reduced candy by 11 rather than 12 as you'd always
83.     get 1 candy back after each evolution*/
84.     seconds = counter * 21; /*Pidgey evolutions take 21 seconds. This line multiplies each evolved pidgey by 21*/
85.     minutes = seconds / (double) 60; /*This divides the total seconds by 60, the result of that is the total amount of minutes spent
86.     on an evolution. Minutes are represented in decimal.*/
87.    }
88. printf("You can evolve %d Pidgeys.\n", counter); /*Message shows total amount of Pidgeys that can be evolved with the user's inputs*/
89. printf("With a lucky egg, you should receive %dxp.\n", xp = counter * 1000); /*Message shows total amount of experience points the user receives with the addition of a lucky egg by multiplying
90. the total evolutions by 1000. One evolution gives 500 xp points, with a lucky egg, it doubles to 1000 xp points.*/
91. printf("The evolution process will take %.2lf minutes.\n", minutes); /*This displays how many minutes the whole process will take*/
92. printf("You will also have %d Pidgeys and %d candy remaining.", pidgey, candy); /*This displays how many pidgeys weren't evovled due to a lack of candy,
93. and how much candy you have left*/
94. }
95. }