samedi 7 février 2015

If else statements, while loop broken

I'd like to preface this with what will become obvious in that I am extremely new to programming and have much to learn. So I'm having a problem where my nested if else statements are being ignored. The second and third "printf" statements are integers but are converted into decimals, since they are the percent discount being applied to the price for medium and large orders. I'm using a while loop to test 3 conditions and if they are all met the message is printed, however if they are not met, I have made 3 if and if else statements to test for which condition is not being met. However , I have missed something as they are not being accurately printed.The base widget cost should not be higher than the base price, med price, or the large price, as this will make the widget sold at a loss. I'm not sure what I'm doing wrong, besides my confusing names that are too similar.



#include <math.h>
#include <stdio.h>
#define widget_cost 0.40

int main (){


float sellprice;
int discount_med;
float discount_med_price;
float med_price;
float large_price;
int discount_large;
float discount_large_price;



printf("How much are you selling each widget for\n");
scanf("%f", &sellprice);

printf("What are you discounting medium orders?\n");
scanf("%f", &discount_med);

printf("What are you discounting large orders?\n");
scanf("%f", &discount_large);

discount_med_price=discount_med/100 * sellprice;
med_price= sellprice-discount_med_price;

discount_large_price=discount_large/100 * sellprice;
large_price=sellprice-discount_large_price;


while (sellprice>widget_cost && med_price>widget_cost && large_price>widget_cost){

printf("All prices look good to me!\n");
printf("Good luck!\n");
}


if (widget_cost>sellprice){
printf("Nick, your base price is too low!");
printf("Good luck!\n");
}
else if (widget_cost>med_price){
printf("Nick, you are discounting medium purchases too much!\n");
printf("Good luck!\n");
}
else if (widget_cost>large_price){
printf("Nick, you are discounting large purchases too much!\n");
printf("Goof luck!\n");
}
return 0;
}

Aucun commentaire:

Enregistrer un commentaire