i am having problems getting my math to work in the if-else statements. i am getting no errors when i run the program but the math for everything past my first if statement shows outrageous numbers in the printf function.
Code:#include <stdio.h> int main() { float total; int hotdogs, hamburgers, salad, pickles; float hotdogval, hamburgerval, saladval, pickleval; hotdogval=1.00, hamburgerval=0.50, saladval=0.25, pickleval=0.01; int picnic() { while(total != 0) { if (total>=1.00) { hotdogs=total*hotdogval; total=total-hotdogs; break; } else if(total>=0.50||total<1.00) { total=total-hotdogs; hamburgers=total*hamburgerval; total=total-hamburgers; break; } else if(total>=0.25||total<0.50) { total=total-hamburgers; salad=total*saladval; total=total-salad; break; } else { total=total-salad; pickles=total*pickleval; break; } }; }; printf("Enter the amount of money to spend:"); scanf("%f", &total); picnic(total); printf("\nthe number of hotdogs you have is %d", hotdogs); printf("\nthe number of hamburgers you have is %d", hamburgers); printf("\nthe number of salads you have is %d", salad); printf("\nthe number of pickles you have is %d", pickles); return 0; };



LinkBack URL
About LinkBacks


