功能问题 [英] Function Problem

查看:94
本文介绍了功能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一个程序可以给出一个可以均匀分割的整数的美分变化。但是它只给出每个面额的变化量。

,例如55美分=

1 50美分

2 20美分

5 10美分

11 5美分>

但它应该输出

1 50美分

0 20美分

0 10美分

1 5分

展开 | 选择 | Wrap | 行号

解决方案


Becasue i C你不能获得超过1的值,我怎样才能在每次循环回到main之后得到美分变量?



您可以返回结构或通过引用传递。通过引用传递可能是更好的选择。

按引用传递


通过引用传递,传入地址而不是值。


好的谢谢生病了,然后报告回来。


嗯我不知道怎么把它引回到main,我输入像Calculate_Coins这样的东西(安培;美分)?

Hi i have a program that gives the cents change of an integer that is divisble evenly 5. However it gives the amount of change for each denomination only.
e.g. 55 cents =
1 50 cent
2 20 cent
5 10 cent
11 5 cent

But it should output
1 50 cent
0 20 cent
0 10 cent
1 5 cent

Expand|Select|Wrap|Line Numbers

解决方案

Becasue i C you cant get more than 1 value back, how would i get the cents variable to be changed after each loop back in main?.

You can either return a structure or pass by reference. Pass by reference is probably the better option.

Pass By Reference

With pass by reference, you pass in the address instead of the value.


Ok thanks ill give it a go and report back.


hmmm im not sure how to reference it back to main, do i input something like Calculate_Coins (&cents)?


这篇关于功能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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