#include <stdio.h>
void main()
{
int unit_price = 350;
int quantity = 0;
int discont = 0;
int total_price = 0;
int dollar = 0;
int cent = 0;
printf("\nEnter the number that you want to buy:");(这里可以输入一个5 用long变量定义的正确结果应该是17.5 用int变量定义结果就不对)
scanf("%d",&quantity);
if(quantity > 10)
discont = 5;
total_price = unit_price * quantity *(100-discont) / 100;
dollar = total_price / 100;
cent = total_price % 100;
printf("\nThe price for %d is $%d.%d.",quantity,dollar,cent);
getch();
}
这个程序用long变量定义就可以 用int变量定义最后输出的结果为什么就不对呢?我输入的值的范围也没超过int值的范围啊 这是为什么谁知道啊?
我是新手 编译器用的是。WIN TC 也许是编译器的问题。