1. ## Pokemon - repost

Hi, i am very new to c programming and I'm asked to write a c program to calculate the maximum amount of experience points (XP) that a Pokémon Go player can earn by using a Lucky Egg bonus timer and evolving Pidgey pokemons.
The program must:

1) Read 2 input numbers. The first input is the number of Pidgey pokemons and the second input is the amount of pidgey candy that the player currently has in their inventory.

2) Display the maximum amount of XP that the player can earn by using a Lucky Egg bonus timer and evolving Pidgey pokemons.

3) Display informative error messages for unexpected or missing input values.

Will appreciate any sort of help! thank you.
(users will need 12 or above candies to evolve 1 pidgey. 1 evolve gives 500 exp. with lucky egg the exp is doubled, in this case 1000xp bare evolve.

How do I make a code so that once the user inputs the amount of pidgeys they got, whatever the input is, it is multipled by 1000, and as a new output for ( exp gained)

e.g.

User puts in 10 pidgeys,
10*1000 = 10000
exp earned = 10,000

Code:
```#include <stdio.h>
int main()
{
int number1, number2, number3, a = 1000;
printf("Enter number of Candies: ");
scanf( "%d", &number1 );
if  ( number1 >= 12 )
printf( "Number is above of 12. You have enough Candies \n" );
if (number1 < 12 )
{
printf ("You do not have enough Candies.!");
exit(-1);
}

printf("Enter number of pidgeys: ");
scanf( "%d", &number2 );
if ( ( number1 > 0 ) )
printf( "Number is above of 0. You have enough Pidgies \n" );
if (number1 < 1 )
{
printf ("You do not have enough Pidgeys.!");
exit(-1);
}

}```

2. > scanf( "%d", &number2 );
> if ( ( number1 > 0 ) )
Shouldn't you be comparing number2, after reading number2?

Looking at number1 again seems pointless.

3. sorry, the number1 was a type error. was meant to read number2.

Code:
```#include <stdio.h>

int main()
{
int number1, number2, number3, a = 1000;

printf("Enter number of Candies: ");
scanf( "%d", &number1 );

if( number1 >= 12 )
printf( "Number is above of 12. You have enough Candies \n" );

if( number1 < 12 )
{
printf ("You do not have enough Candies.!");
exit(-1);
}

printf("Enter number of pidgeys: ");
scanf( "%d", &number2 );

if( ( number1 > 0 ) )
printf( "Number is above of 0. You have enough Pidgies \n" );
if( number1 < 1 )
{
printf ("You do not have enough Pidgeys.!");
exit(-1);
}
}```
Be sure you are compiling with maximum warnings:

Code:
```main.c||In function 'main':|
main.c|16|warning: implicit declaration of function 'exit'|
main.c|16|warning: incompatible implicit declaration of built-in function 'exit'|
main.c|27|warning: incompatible implicit declaration of built-in function 'exit'|
main.c|5|warning: unused variable 'a'|
main.c|5|warning: unused variable 'number3'|```
You need to include stdlib.h for exit().

Originally Posted by sureme
How do I make a code so that once the user inputs the amount of pidgeys they got, whatever the input is, it is multipled by 1000, and as a new output for ( exp gained)

e.g.

User puts in 10 pidgeys,
10*1000 = 10000
exp earned = 10,000
You already seem to know how to read an integer into a variable. Now you just need to multiply that value by 1000.

Code:
`exp_earned = pidgeys * 1000;  // arbitrary variable names`
This is covered in any introductory text. I suggest you get a good book, read through it sequentially, and do all the examples and exercises.

5. Hi, thank you for the reply. Really appreciate it. I will fix the neatness of the program shortly before its final. I included the stdlib.h for exit().
and works well.

However, regards to the:exp_earned = pidgeys * 1000; // arbitrary variable names

I played around with it, but I need the program to straight away give me the exp earned (output) once the input of pidgeys is entered and is above 0.
To evolve once the user must have 1 piglet and 12 candies. Then once it meets the criteria the calulcation of (the emount of pidgets) * 1000 should be displayed as the output. Sorry if I am confusing you or sound stupid. Only started programming a week ago or so .

6. I will fix the neatness of the program shortly before its final.
Messing code is likely to be ignored; decide if you wish to be ignored.

If it is NOT worth your time to format the code; why should anyone spend time trying to help you?

Tim S.

7. Code:
```#include <stdio.h>
int main()
{
int number1, number2;
printf("Enter number of Candies: ");
scanf( "%d", &number1 );
if  ( number1 >= 12 )
printf( "Number is above of 12. You have enough Candies \n" );
if (number1 < 12 )
{
printf ("You do not have enough Candies.!");
}
printf("Enter number of pidgeys: ");
scanf( "%d", &number2 );
if ( ( number2 > 0 ) )
printf( "Number is above of 0. You have enough Pidgies \n" );
if (number1 < 1 )
{
printf ("You do not have enough Pidgeys.!");
}

}```

I don't get any errors now, sorry

8. Originally Posted by sureme
Hi, thank you for the reply. Really appreciate it. I will fix the neatness of the program shortly before its final. I included the stdlib.h for exit().
and works well.
You should be formatting your code as you're writing it. This not only helps development, but also helps you avoid mistakes. And, as stahta01 mentioned, you are more likely to get help if your code is readable.

Originally Posted by sureme
However, regards to the:exp_earned = pidgeys * 1000; // arbitrary variable names

I played around with it, but I need the program to straight away give me the exp earned (output) once the input of pidgeys is entered and is above 0.
To evolve once the user must have 1 piglet and 12 candies. Then once it meets the criteria the calulcation of (the emount of pidgets) * 1000 should be displayed as the output. Sorry if I am confusing you or sound stupid. Only started programming a week ago or so .
The second part of that statement says you need to output the value multiplied by 1000 after criteria has been checked, but the first part says "straight away".

This would be a good time to learn logic development. Get a pencil and paper, and list the steps by hand that you need to follow. Once the logic is developed and verified, start converting each step to code. (This gets easier with experience, so I'd strongly recommend you start now.)

Perhaps something like this:

Code:
```read the number of candy
if the number of candy is not correct
print error message
else
if the number of piglets is not correct
print error message
else
multiply value by 1000
print value```

Your latest post still does not have consistent indentation. Every time there's an opening brace { (or where an opening brace is optional), indent one level. When there's a closing brace }, un-indent one level. Study the example I posted above.

Also, use meaningful variable names so your code is self-documenting. Instead of "number1" and "number2", use something like "candies" and "pidgeys". This makes your code more clear and easier to read.

9. Hi mate this is what I have done so far... And the task is due tonight. I cannot get the while function to work properly...Any help is appreciated!

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;
}```

10. Your formatting still needs work.

Also, you should explain your problem more clearly. Tell us what is the while() supposed to do, and how is it not working.

"PossibleEvolutions" is never initialized, but used in several places. That is certainly one problem.

If experience is only rewarded if the user enters the correct number of "candies" and "pidgeys", you should skip the experience calculations if one of these inputs is not a valid value. This is as simple as setting flags if either of those inputs is not valid, and skipping the experience calculation if either of those flags are set.

Code:
```Exp = Pidgey*1000;
printf("total exp with lucky egg was %d", Pidgey);```
Did you mean to use "Exp" in the printf()? Or maybe even "XPWithLuckyEgg"?

11. 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).

12. Okay basically the IF functions at the start is suppose to save the data the person inputs. For example; 120 Candies and 10 Pidgeys.
For every 12 candies and 1 pidgeys, that is 1 evolution. so with 10 pidgeys and 120 candies, I can evolve a total amount of 10 times with the 120 candies. That is what I tried to do in the WHILE function.
Every evlolve shoud : -12 candies, +1000 exp, -1 pidey.

Once the pidgey is evolved, it turns into Pideottos, and EXWithLuckyEgg should be calculated by Pideottos * 1000.

13. Also just adding on, "PossibleEvolutions" I put in so that it shows how many times a user can evolve depending on the entered input. Again with 120 candies and 10 pidgeots, then PossibleEvolutions should display "10 possible evolutions". Sorry I forgot to mention this

14. Perhaps your first while loop should be
Code:
```// -12 candies, +1000 exp, -1 pidey.
while ( Candies > 0 && Pidgeys > 0 ) {
Candies -= 12;
Pidgeys -= 1;
exp += 1000;  // don't forget to initialise these to 0
evolutions++;
}```

15. Originally Posted by Salem
Perhaps your first while loop should be
Code:
```// -12 candies, +1000 exp, -1 pidey.
while ( Candies > 0 && Pidgeys > 0 ) {
Candies -= 12;
Pidgeys -= 1;
exp += 1000;  // don't forget to initialise these to 0
evolutions++;
}```

What do you mean by initialise ?
Thank you so much for the replies also.