设计一个程序,计算销售价格。某个用品店需要一个程序可以在输入商品的原始价格(OriginalPrice)和折扣率(DiscountRate)之后,计算并输出该折扣商品的最终价格(SalePrice)。
#include
void welcome();
int input(int n,int m);
int computer(int q,int n,int m);
int output(int n,int m,int q);
int main()
{
int n,m,p;
welcome();
input(n , m);
computer(q , n , m);
output(n , m , q);
}
void welcome()
{
printf("Welcome to sale price program\nThis program computes the saleprice of an item that has been discounted a certain percentage.\n");
}
int input(int n,int m)
{
printf("What is the price: ");
scanf("%i",&n);
printf("\nWhat is the percentage dicounted: ");
scanf("%i",&m);
return n,m;
}
int computer(int q,int n,int m)
{
q = n * (1 - m/100);
return q;
}
int output(int n,int m,int q)
{
printf("\npre-price was: %i",n);
printf("\nprecentage discounted was: %i",m);
printf("\nsale price is: %i",q);
}
Welcome to sale price program
This program computes the saleprice of an item that has been discounted a certain percentage.
What is the price: 100
What is the percentage dicounted: 10
pre-price was: 16
precentage discounted was: 449
sale price is: 0
不知道为何最后是乱码
pre-price was: 100
precentage discounted was: 10
sale price is: 90
scanf("%i",&n);
好像没有%i吧,改成%d
return n,m;---这个写法是很神奇的,自己想的是返回两个整数,可实际只能返回m的值。如果要返回两个整数,请将参数改为指针类型