怎么进行C语言编程,要全代码

2024-11-09 02:06:44
推荐回答(5个)
回答1:

#include


main()

{

char goods[4][20] = {"","T 恤","网球鞋","网球拍"};

float cost[4] = {0,245.0,570.0,600.0};

char c;

int num;

int n;

float total;

float pay;

float dis;


printf("******************************\n");

printf("请选择购买的商品编号:\n");

printf("1.T 恤   2.网球鞋   3.网球拍\n");

printf("******************************\n");

total = 0;

dis = 0.8;

do{

        printf("\n");

        printf("请输入商品编号:");

        scanf("%d",&num);

        printf("请输入购买数量:");

        scanf("%d",&n);

        printf("%s¥%0.1f   数量 %d   合计 ¥%0.1f\n",goods[num],cost[num],n,n * cost[num]);

        total += n * cost[num];

        printf("是否继续(y/n)");

        c = getchar();

        scanf("%c",&c);

}while(c == 'y');

printf("\n折扣:%0.1f\n",dis);

printf("应付金额:%0.1f\n",total * dis);

printf("实付金额:");

scanf("%f",&pay);

printf("找现:%0.1f\n",pay - total * dis);

}

回答2:

#include


void main()

{

int m;

int sum=0;

int num;

int count;

char val;

while(1)

{

printf("请输入商品编号:");

scanf("%d",&num);

printf("请输入商品数量:");

scanf("%d",&count);

if(num==1)

{

printf("T恤 ¥ 245.0  数量%d   合计¥ %d \n",count,count*245);

sum += count*245;

}

if(num==2)

{

printf("网球鞋 ¥570.0 数量 %d   合计¥ %d \n",count,count*570);

sum += count*570;

}

printf("是否继续(y/n)");

scanf("%c",&val);

scanf("%c",&val);

if(val=='n')

break;

}

printf("折扣 0.8\n");

printf("应付金额%d\n",sum);

printf("实付金额:");

scanf("%d",&m);

printf("找钱%d\n",m-sum);


return;

}

ok

回答3:

需要一个编译器如dev c++(推荐),vc等
在编译器里新建一个cpp文件,写代码如下:
#include
int main()
{
int total=0,id,n,a[3]={245,570,网球拍价格};
char x;

while (1)
{
printf("输入商品编号:");

scanf("%d",&id);
printf("\n输入购买数量:");
scanf(%d",&n);
if(id==1) {printf("T恤:245 数量:%d 合计:%d",a[0]*n);total+=a[0]*n;}

if(id==2) {printf("网球鞋:570 数量:%d 合计:%d",a[1]*n);total+=a[1]*n;}
if(id==3) {printf("网球拍:网球拍价格我不知道 数量:%d 合计:%d",a[2]*n);total+=a[2]*n;}
printf("\n继续?(y/n)");
scanf("%c",&x);

if (x=='n') break;
}
printf("折扣:0.6“);
printf("应付价格:%d",total*0.6);
printf("实付金额:");
int money;

scanf("%d",&money);
printf("找零:%d",money-total);
return 0;

}

p.s 我直接在网页里打得也没有编译,复制去试试应该没什么问题,可能也就一些格式啊什么的,关于金额,可以在a[3]={...,...,...}这里变,反正先看懂应该没问题

回答4:

#include "stdio.h"
void main()
{
printf("*************************************\n");
printf("请选择购买的商品编号:\n");
printf("1. T恤 2.网球鞋 3.网球拍\n");
printf("*************************************\n");
inter number, count, pay;
float sum=0;
float a;
char flag='Y';
while(flag=='Y' or flag=='y')
{
printf("请输入商品编号:");
scanf("%d",&number);
printf("请输入购买数量:");
scanf("%d",&count);
switch(number)
{
case 1:
printf("T恤¥245.0 数量%d 合计¥ %.1f\n",count, 245*count);
sum+=245*count;
break;
case 2:
printf("网球鞋¥570.0 数量%d 合计¥ %.1f\n",count, 570*count);
sum+=570*count;
break;
case 3:
printf("网球拍¥300.0 数量%d 合计¥ %.1f\n",count, 300*count);
sum+=300*count;
break;
default:
printf("商品编号输入错误!\n");
}
printf("是否继续(y/n)");
scanf("%c",flag);
}
printf("折扣:");
scanf("%f",&a);
printf("应付金额:%.1f",sum*a);
printf("实付金额:");
scanf("%d",&pay);
printf("找钱:%.1f",pay-sum*a);
}

回答5:

codecodecode