如何添加此功能以使其工作?在C. [英] How do I add this function to make this work? In C

查看:85
本文介绍了如何添加此功能以使其工作?在C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改代码,使其包括以下函数:



void pay_amount(int dollars,int * Twenties,int * tens,int * fives,int *


该函数确定支付美元参数所代表金额所需的20美元,10美元,5美元和1美元的最小数量。二十个参数指向一个变量,其中函数将存储所需的20美元钞票的数量。几十个和一个参数是相似的。





我对如何添加这个很困惑,我试了一会但是我很累,然后去睡觉了。



我尝试了什么:



Modify the code so that is includes the following function:

void pay_amount (int dollars, int *twenties, int *tens, int *fives, int *ones);

The function determines the smallest number of $20, $10, $5, and $1 bills necessary to pay the amount represented by the dollars parameter. The twenties parameter points to a variable in which the function will store the number of $20 bills required. The tens fives and ones parameters are similar.


I'm quite confused on how to add this, I tried for awhile but I was tired and went to sleep.

What I have tried:

int main(void)
{
  int amount, twenties, tens, fives, ones, reduced_amount;

  printf("Enter a dollar amount: ");
  scanf("%d", &amount);

  twenties = amount / 20;
  reduced_amount = amount - (20 * twenties);

  tens = reduced_amount / 10;
  reduced_amount = reduced_amount - (10 * tens);

  fives = reduced_amount / 5;
  ones = reduced_amount - (5 * fives);

  printf("\n");   /* blank line */

  printf("$20 bills: %d\n", twenties);
  printf("$10 bills: %d\n", tens);
  printf(" $5 bills: %d\n", fives);
  printf(" $1 bills: %d\n", ones);

  return 0;
}

推荐答案

20,


10,


5,和


这篇关于如何添加此功能以使其工作?在C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆