初学C语言,明明按照书上输入的,但是有错误,我仔细看了几遍确实没有发现错误,请给位帮我指正!
下面上源代码#include<stdo.h>intmain(void){constdoubleunit_price=3.50;constdoublediscount1=0...
下面上源代码
#include <stdo.h>
int main(void)
{
const double unit_price = 3.50;
const double discount1 = 0.05;
const double discount2 = 0.1;
const double discount3 = 0.15;
double total_price = 0.0;
int quantity = 0;
printf("Enter the number that you want to buy:"); /* 就是这一行有错误 */
scanf(" %d", &quantity);
total_price = quantity*unit_price*(1.0 -
(quantity > 50 ? discount3 : (
quantity > 20 ? discount2 : (
quantity > 10 ? discount1 : 0.0)));
printf("The price for %d is $%.2f\n", quantity, total_price);
return 0;
} 展开
#include <stdo.h>
int main(void)
{
const double unit_price = 3.50;
const double discount1 = 0.05;
const double discount2 = 0.1;
const double discount3 = 0.15;
double total_price = 0.0;
int quantity = 0;
printf("Enter the number that you want to buy:"); /* 就是这一行有错误 */
scanf(" %d", &quantity);
total_price = quantity*unit_price*(1.0 -
(quantity > 50 ? discount3 : (
quantity > 20 ? discount2 : (
quantity > 10 ? discount1 : 0.0)));
printf("The price for %d is $%.2f\n", quantity, total_price);
return 0;
} 展开
3个回答
展开全部
#include <stdio.h> /*头文件*/
int main(void)
{
const double unit_price = 3.50;
const double discount1 = 0.05;
const double discount2 = 0.1;
const double discount3 = 0.15;
double total_price = 0.0;
int quantity = 0;
printf("Enter the number that you want to buy:"); /* 就是这一行有错误 */
scanf(" %d", &quantity);
total_price = quantity*unit_price*(1.0 -
(quantity > 50 ? discount3 : (
quantity > 20 ? discount2 : (
quantity > 10 ? discount1 : 0.0))));/*少个括号*/
printf("The price for %d is $%.2f\n", quantity, total_price);
return 0;
}
你的编译器是中文还是英文的,学会自己看编译提示最好的
追问
多谢提示。 我的编译器是DEV C++,全是英文。能不能发给我哥好用的中文编译器。381069463艾特qq.com
追答
做开发最好习惯用英文的,我一般用vs英文版,中文版翻译的都不好。我开始我用TC,要发给你就win-TC吧 比较小巧实用。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询