谢谢大哥 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日

悬赏问题

  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据