谢谢大哥 2022-10-25 15:22 采纳率: 100%
浏览 27
已结题

关于c语言程序的问题,如何解决?

问题遇到的现象和发生背景

设计一个程序,计算销售价格。某个用品店需要一个程序可以在输入商品的原始价格(OriginalPrice)和折扣率(DiscountRate)之后,计算并输出该折扣商品的最终价格(SalePrice)。

用代码块功能插入代码,请勿粘贴截图

#include <stdio.h>

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

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-10-25 15:37
    关注

    scanf("%i",&n);
    好像没有%i吧,改成%d
    return n,m;---这个写法是很神奇的,自己想的是返回两个整数,可实际只能返回m的值。如果要返回两个整数,请将参数改为指针类型

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 11月11日
  • 已采纳回答 11月3日
  • 创建了问题 10月25日

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题