有关C语言整型变量的问题 知道的请进

#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 也许是编译器的问题。

第1个回答  2008-08-05
如果你是用VC的话,应该是VC没有重新编译,导致数据没有更新
第2个回答  2008-08-04
VC上没问题,不知你用的什么编译器本回答被提问者采纳
第3个回答  2008-08-05
VC没问题
相似回答
大家正在搜