While Loops.... why does it ask me to enter the value twice?
Hey guys, been trying to figure this while loop stuff out. Just started learning C, and I am new to programming all together. Basically what I have are 3 products each a a specific price, but I want to change the price of the product by a specific percent, and must be less than 50%. The problem is when it asks me how much to increase the product, I have to enter it twice, any ideas on why.
Code:
float appleChange;
float apples;
float newAppleIncrease;
apples=2.2;
newAppleIncrease=0;
/*Some other stuff here*/
printf("Please type in the new percent price change to be applied to apples\n");
scanf("%f\n", &appleChange);
if (appleChange > .5){
while (appleChange > .5){
printf ("Please make a change that is less than .5");
scanf("%f \n", &appleChange);
}
}
while (newAppleIncrease<=2.2){
newAppleIncrease = (apples * appleChange)+apples;
printf("The new price for the apples is %.2f \n",newAppleIncrease);
}