帮忙写一个C语言程序~~~>.<(在线等,有问题请发信息给我)

1.有4种type的文具,其价格如表1,购买的总数与打折率关系如表2.

2.允许一起购买2种以上的type.

3.最起码要体现出2种以上的函数:

1)要给出各type的金额计算函数;
2)一定要写出打折率应用的函数.

表1:
┌———┬———┐
│种类 │ 价格 │
├———┼———┤
│A type│ 5000 │
├———┼———┤
│B type│ 6000 │
├———┼———┤
│C type│ 7000 │
├———┼———┤
│D type│ 8000 │
└———┴———┘

表2:

购买总数与打折率的关系:
┌—————————————┬————┐
│ 购买的总数 │ 打折率 │
├—————————————┼————┤
│10个以上-30个(不包含30个) │ 10% │
├—————————————┼————┤
│30个以上-50个(不包含50个) │ 15% │
├—————————————┼————┤
│50个以上 │ 20% │
└—————————————┴————┘

┌————输出形态1———————————┐

请输入想要购买的文具种类和数量.

购买的文具种类:A/B/C/D

购买的数量: * * *

想要选择购买其他种类的文具吗:Yes/No

└———————————————————┘

(注释:
1.如果选择Yes,将返回 "输出形态1"框下的菜单.

2.如果选择No,则转向"输出形态2".

┌—————输出形态2—————————┐

文具结算单

A type 文具购买数量:
B type 文具购买数量:
C type 文具购买数量:
D type 文具购买数量:

购买文具总数:

打折前所需金额:

打折金额:

结算金额:

└———————————————————┘

(注释:打折前所需金额-打折金额=结算金额)
因为初学,所以尽量用比较基础的语句~~谢谢^^

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void main()
{
int i, choice, type, tn, num[4], price[4], totalnum, totalprice;
double discount, discprice;

price[0] = 5000;
price[1] = 6000;
price[2] = 7000;
price[3] = 8000;

num[0] = num[1] = num[2] = num[3] = 0;

choice = 'Y';
while (choice == 'Y')
{
printf("请输入想要购买的文具种类和数量\n");
printf("购买的文具种类(A/B/C/D):");
type = 0;
while (type < 'A' || type > 'D')
{
type = getch();
type = toupper(type);
}
printf("%c\n", type);
printf("购买的数量:");
while (!scanf("%d", &tn))
{
printf("Input error, try again!");
fflush(stdin);
}
num[type - 'A'] += tn;
printf("想要选择购买其他种类的文具吗(Yes/No):");
choice = 0;
while (choice != 'Y' && choice != 'N')
{
choice = getch();
choice = toupper(choice);
}
printf("%c\n", choice);
}
printf("文具结算单\n");
for (i = 0; i < 4; i++)
{
printf("%c type 文具购买数量:%d\n", 'A' + i, num[i]);
}

totalnum = num[0] + num[1] + num[2] + num[3];
printf("购买文具总数:%d\n", totalnum);
totalprice = num[0] * price[0] + num[1] * price[1] + num[2] * price[2] + num[3] * price[3];
printf("打折前所需金额:%d\n", totalprice);
switch (totalnum / 10)
{
case 0:
discount = 0.0f;
break;
case 1:case 2:
discount = 0.1f;
break;
case 3:case 4:
discount = 0.15f;
break;
default:
discount = 0.2f;
}
discprice = totalprice * discount;
printf("打折金额:%1.1f\n", discprice);
printf("结算金额:%1.1f\n", totalprice - discprice);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-10-14
在VC6.0上调是通过,程序没有加入如果输错了该怎么处理,我想这个东西应该由你自己完成了,帮到这里了!!!呵呵,不过你可以参考楼上的哦!!

#include <stdio.h>
#include <string.h>
#include <iostream.h>

#define PRICEA 5000
#define PRICEB 6000
#define PRICEC 7000
#define PRICEd 8000

float CaculateA(int num)
{
float total;
total = num * PRICEA;

return total;
};

float CaculateB(int num)
{
float total;
total = num * PRICEA;

return total;
};

float CaculateC(int num)
{
float total;
total = num * PRICEA;

return total;
};

float CaculateD(int num)
{
float total;
total = num * PRICEA;

return total;
};

float CaculateTotal(int a, int b, int c, int d) //计算不打折的总钱数
{
return CaculateA(a) + CaculateB(b) + CaculateC(c) + CaculateD(d);
};

float Discount(int a, int b, int c, int d) //计算折扣
{
int totalNum = 0;
float discount;
totalNum = a + b + c + d;

if (totalNum >= 10 && totalNum < 30)
{
discount = CaculateTotal(a, b, c, d) * 0.1;
}
else if (totalNum >= 30 && totalNum < 50)
{
discount = CaculateTotal(a, b, c, d) * 0.15;
}
else if (totalNum >= 50)
{
discount = CaculateTotal(a, b, c, d) * 0.2;
}

return discount;
};

float Pay(int a, int b, int c, int d) //计算最后应该付的钱
{
return CaculateTotal(a, b, c, d) - Discount(a, b, c, d);
};

void main()
{
int numA = 0;
int numB = 0;
int numC = 0;
int numD = 0;
int temp = 0;
int type;
int contiune;

do
{
printf("请输入想要购买的文具种类和数量\n");
printf("购买的文具种类 : ");
cin >> type;
printf("购买的数量 : ");
scanf("%d", &temp);

switch (type)
{
case 'a':
case 'A':
numA += temp;
break;
case 'b':
case 'B':
numB += temp;
break;
case 'c':
case 'C':
numC += temp;
break;
case 'd':
case 'D':
numD += temp;
break;
default:
break;
}

printf("想要选择购买其他种类的文具吗 : ");
cin >> contiune;
}while(contiune == 'y' || contiune == 'Y');

printf("\nA type 文具购买数量 : ");
printf("%d\n", numA);
printf("B type 文具购买数量 : ");
printf("%d\n", numB);
printf("C type 文具购买数量 : ");
printf("%d\n", numC);
printf("D type 文具购买数量 : ");
printf("%d\n\n", numD);

printf("购买文具总数 : ");
printf("%d\n\n", numA + numB + numC + numD);

printf("打折前所需金额 : ");
printf("%.2f\n\n", CaculateTotal(numA, numB, numC, numD));

printf("打折金额 : ");
printf("%.2f\n\n", Discount(numA, numB, numC, numD));

printf("结算金额 : ");
printf("%.2f\n\n", Pay(numA, numB, numC, numD));
}