如何在不使用全局变量的情况下使用外部使用的整数编写函数? [英] How do you write a function with integers used outside without using globals?

查看:58
本文介绍了如何在不使用全局变量的情况下使用外部使用的整数编写函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想要得到这个,但无论我尝试什么方法,都没有用,本书只展示了最简单的例子。我目前运行其他功能,但具有全局值。我想解决所有问题,但要做到这一点,我需要使用以下函数:


函数原型:

int ToTaling(int& ;,int&,int&,int&,int&,int&,int&,int&,int&);

(OR)

// int& TotalRate,int& TotalRegHours,int& TotalOvtHours,int& TotalGrossPay,

/ / int& TotalFedTax,int& TotalStateTax,int& TotalSSITax,int& TotalDeferred,

// int& TotalNet);

(我尝试过实际的名字,我尝试用*而不是&符号,我在这里缺少什么?我在开始时也试过了。似乎没什么用。)


(里面主要)

int TotalRate,TotalRegHours,TotalOvtHours,TotalGrossPay,TotalFedTax,

TotalStateTax,TotalSSITax,TotalDeferred,TotalNet;


ToTaling (& TotalRate,& TotalRegHours,& TotalOvtHours,& TotalGrossPay,

& TotalNet);


然后是主要的功能:

{

int J = 0 ;

而(J <= H){

TotalRate = TotalRate + Payrate [J]; //等于总数+ =小时[J + 1];

TotalRegHours = TotalRegHours + RegHours [J]; //等于总数+ =小时[J + 1];

TotalOvtHours = TotalOvtHours + OvtHours [J];

TotalGrossPay = TotalGrossPay + CalcGross [J];

TotalFedTax = TotalFedTax + calcFed [J];

TotalStateTax = TotalStateTax + calcState [J];

TotalSSITax = TotalSSITax + calcSSi [J];

TotalDeferred = TotalDeferred + Deferred [J];

TotalNet = TotalNet + NetPay [J]; //等于总数+ =小时数[J + 1];

J = J + 1;

}


返回( TotalRate,TotalRegHours,TotalOvtHours,TotalGrossPay,TotalFedTax,TotalStateTax,TotalSSITax,TotalDeferred,TotalNet);

}


我得到的当前错误是:无法将参数1从''int *''转换为''int&'' ....

以下行:

& TotalNet); (主要的,虽然可能是整个事情!)


感谢您的帮助!

I''ve been trying to get this, but no matter what method I try, nothing works and the book shows only the most simplistic examples. I have other functions currently that run, but with global values. I want to fix it all, but to do that, I need to get the following function to work:

function prototype:
int ToTaling(int &,int &,int &,int &,int &,int &,int &,int &,int &);
(OR)
//int &TotalRate, int &TotalRegHours, int &TotalOvtHours, int &TotalGrossPay,
// int &TotalFedTax, int &TotalStateTax, int &TotalSSITax, int &TotalDeferred,
// int &TotalNet);
(I tried it with the actual names, I tried it with * instead of ampersand, what am I missing here? I''ve also tried void at the beginning. Nothing seems to work.)

(inside main)
int TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,
TotalStateTax,TotalSSITax, TotalDeferred,TotalNet;

ToTaling(&TotalRate,&TotalRegHours,&TotalOvtHours, &TotalGrossPay,
&TotalFedTax,&TotalStateTax,&TotalSSITax,&TotalDef erred,
&TotalNet);


And then the function outside the main:
{
int J = 0;
while (J<=H){
TotalRate=TotalRate+Payrate[J]; // equals Total += Hours[J+1];
TotalRegHours=TotalRegHours+RegHours[J]; // equals Total += Hours[J+1];
TotalOvtHours=TotalOvtHours+OvtHours[J];
TotalGrossPay=TotalGrossPay+CalcGross[J];
TotalFedTax=TotalFedTax+calcFed[J];
TotalStateTax=TotalStateTax+calcState[J];
TotalSSITax=TotalSSITax+calcSSi[J];
TotalDeferred=TotalDeferred+Deferred[J];
TotalNet=TotalNet+NetPay[J]; // equals Total += Hours[J+1];
J=J+1;
}

return (TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,TotalStateTax, TotalSSITax, TotalDeferred, TotalNet);
}

The current error I''m getting is : cannot convert parameter 1 from ''int *'' to ''int &'' ....
The following line:
&TotalNet); (in the main, though probably the entire thing!)

Thanks for any and all help!

推荐答案

展开 | 选择 | Wrap | 行号


我得到了正在运行的功能,这要归功于你的目标建议。现在的问题是输出。 -107374160 - 它正在给我这些值而不是实际数字。


在将值打印到文件时,是否需要一个特殊字符来引用它?


我试着回到这些例子而且他们非常无益。从你那里得到一些有用的提示,我实际上到了某个地方...
I got the function running, thanks to your very on target advice. Now the issue is the output. -107374160 --It''s giving me these values in return instead of the actual number.

Do I need a special character to reference back to it when printing the value to a file?

I tried going back to the examples and they''re very unhelpful. A few little helpful hints from you and I''m actually getting somewhere...


Taling的返回值看起来很糟糕
The return value for Taling looks bad

return(TotalRate,TotalRegHours,TotalOvtHours,TotalGrossPay,TotalFedTax,TotalStateTax,TotalSSITax,TotalDeferred,TotalNet);
return (TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,TotalStateTax, TotalSSITax, TotalDeferred, TotalNet);



我不知道如何将这个返回值读入数组或单独的变量。


此外,它看起来你不需要ToTaling返回任何东西,因为参数是通过引用传递的,它们的值由子程序直接改变。

I''m not sure how to read this return value into an array or separate variables.

Also, it looks like you don''t need to have ToTaling return anything because the parameters are passed by reference, and their values are changed directly by the subroutine.


这篇关于如何在不使用全局变量的情况下使用外部使用的整数编写函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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