混乱功能(第二部分) [英] Messing Up Functions (Part II)

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

问题描述

我仍然在处理功能问题。这是我早期搞砸的程序的变种。我正在努力减少每项功能的工作量。我想如果可以让这个工作我可以编辑原始程序到这种格式。


它生成随机数,创建用户命名文件但不写入它。如何获取打印功能echoPrint,从随机数生成器打印数据,以及稍后将从操作数组的其他函数打印数据。


我引用了数组在echoPrint的正式参数列表中,为什么它没有看到它?


我已经尝试过outfile<< firstArray []<< ENDL;并得到此错误:


错误1错误C2059:语法错误:'']''


此外,outfile<< firstArray [randNum]<< ENDL;导致


错误1错误C2065:''randNum'':未声明的标识符


我是否需要使其他功能无效键入并使用返回行将数据发送到echoPrint?

I still messin'' around with functions. This is a variant of the program I was messing up early. I''m trying to reduce the amount of work each function is doing. I figured if could get this to work I can edit the original program to this format.

It''s generating the random numbers, creating the user named file but not writing to it. How do I get the print function, echoPrint, to print data from the random number generator and later on from additional functions that will be manipulating the array.

I''ve referenced the array in the formal parameter list of echoPrint so why doesn''t it see it?

I''ve tried outfile << firstArray [] << endl; and get this error:

Error 1 error C2059: syntax error : '']''

Also, outfile << firstArray[randNum] << endl; which results in

Error 1 error C2065: ''randNum'' : undeclared identifier

Will I need to make the other functions non void type and send the data to echoPrint with a return line?

展开 | 选择 | Wrap | 行号

推荐答案

> ;我已经尝试过outfile<< firstArray []<< ENDL;并得到这个错误:


你不必给[]。如果你的意思是数组中的第一个元素,请指定firsyArray [0]


>另外,outfile<< firstArray [randNum]<< ENDL;导致


>错误1错误C2065:''randNum'':未声明的标识符


这是因为randNum未在那个功能。要么将randNum传递给该函数,要么将其设为全局[我建议前者]。


我是否需要将其他函数设置为非void类型并将数据发送到带回程线的echoPrint?

除非你想要返回值,否则你的函数可以保持无效。我建议将数据作为参数传递。我不明白为什么函数需要返回数据。这取决于你的要求。

>I''ve tried outfile << firstArray [] << endl; and get this error:

You do not have to give the []. If you meant the first element in the array, specify firsyArray[0]

>Also, outfile << firstArray[randNum] << endl; which results in

>Error 1 error C2065: ''randNum'' : undeclared identifier

That is because randNum is not declared in that function. Either pass randNum to that function, or make it global [i suggest the former].


Will I need to make the other functions non void type and send the data to echoPrint with a return line?

Your functions can stay void unless you want to return values. I suggest passing the data as a parameter. I do not see why the functions need to return data. It is up to your requirement.

展开 | 选择 | Wrap | 行号



>我已经尝试过outfile<< firstArray []<< ENDL;并得到这个错误:


你不必给[]。如果你的意思是数组中的第一个元素,请指定firsyArray [0]
>I''ve tried outfile << firstArray [] << endl; and get this error:

You do not have to give the []. If you meant the first element in the array, specify firsyArray[0]



我的意思是所有元素。放入零或删除括号也不起作用。

I meant all the elements. Putting in a zero or removing the brackets altogether doesn''t work either.


>

>此外,outfile<< firstArray [randNum]<< ENDL;导致


>错误1错误C2065:''randNum'':未声明的标识符


这是因为randNum未在那个功能。要么将randNum传递给该函数,要么将其设为全局[我建议前者]。
>
>Also, outfile << firstArray[randNum] << endl; which results in

>Error 1 error C2065: ''randNum'' : undeclared identifier

That is because randNum is not declared in that function. Either pass randNum to that function, or make it global [i suggest the former].



添加

Adding

展开 | 选择 | Wrap | 行号


echoprint仍未获得randNo是你声明一个int随机数。为什么不在通话期间尝试将其作为参数传递。就像传递int randNO和数组到echoprint
echoprint is still not getting the randNo is you declare a int random number. Why dont you try passing it as a paramter during the call. As is pass int randNO and the array to echoprint


这篇关于混乱功能(第二部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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