//when I am trying to make a division in a float variable for some reason it
//prints 000
#include <stdio.h>
#include <math.h>
int main(){
float price , discount , total ;
scanf ("%f",&price);
if (price > 99 && price < 201)
discount = 10/100;
// i can also set <<discount>> variable 0.10
else if (price < 301)
// but i can t understand why this way prints 00
discount = 10/100;
else if (price <401)
discount = 20/100;
else
discount = 30/100;
total = price - discount;
printf ("tha exete ekptwsei %.2f",discount);
}
答案 0 :(得分:4)
if (price > 99 && price < 301)
discount = 10.0/100.0;
else if (price <401)
discount = 20.0/100.0;
else
discount = 30.0/100.0;
更新 除法器中只有.0就可以满足10 / 100.0