The first thing you need to do is learn how to indent code.
Like so.
Code:
#include <stdio.h>
int main()
{
int Candies, Pidgey, Exp, XPWithLuckyEgg, PossibleEvolutions, Pideottos;
printf("Enter number of Candies: ");
scanf("%d", &Candies);
if (Candies < 12) {
printf("Entered Number is %d \n", Candies);
printf("You do not have enough Candies. \n");
} else {
printf("You have enough Candies. \n");
}
printf("Enter number of Pidgey: ");
scanf("%d", &Pidgey);
if ((Pidgey < 1)) {
printf("Entered Number is %d \n", Pidgey);
printf("You do not have enough Pidgey. \n");
} else {
printf("You have enough Pidgeys. \n");
}
while ((Pidgey >= PossibleEvolutions) && (PossibleEvolutions > 0)) {
Candies -= 12;
XPWithLuckyEgg += 1000;
--Pidgey;
Candies++;
--PossibleEvolutions;
}
while ((PossibleEvolutions >= Pidgey) && (Pidgey > 0)) {
Candies -= 12;
XPWithLuckyEgg += 1000;
--Pidgey;
Candies++;
--PossibleEvolutions;
}
Exp = Pidgey * 1000;
printf("total exp with lucky egg was %d", Pidgey);
//getch();
return 0;
}
Next, compile with as many warnings enabled as possible.
Code:
$ gcc -Wall -Wextra -O2 main.c
main.c: In function ‘main’:
main.c:4:65: warning: unused variable ‘Pideottos’ [-Wunused-variable]
int Candies, Pidgey, Exp, XPWithLuckyEgg, PossibleEvolutions, Pideottos;
^
main.c:4:24: warning: variable ‘Exp’ set but not used [-Wunused-but-set-variable]
int Candies, Pidgey, Exp, XPWithLuckyEgg, PossibleEvolutions, Pideottos;
^
main.c:7:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Candies);
^
main.c:16:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Pidgey);
^
main.c:4:45: warning: ‘PossibleEvolutions’ may be used uninitialized in this function [-Wmaybe-uninitialized]
int Candies, Pidgey, Exp, XPWithLuckyEgg, PossibleEvolutions, Pideottos;
^
The most immediate problem is that PossibleEvolutions isn't initialised, so both your while loops are working with garbage data.
XPWithLuckyEgg isn't used either, except to just keep adding 1000 to it. You never actually use the result in another calculation.
If you do, you need to initialise it.
Your Exp variable is assigned a value, but you never use it (perhaps you meant to print it)?
Next, you should check your scanf results for success, which would typically be of the form
if ( scanf("%d",&Candies) == 1 )
Finally, purely for code clarity, you should delete the unused variables (unless they're part of a plan yet to be implemented).