代码有问题 [英] Got a problem with a code

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

问题描述

#include "stdafx.h"
#include <iostream>
using namespace std;
void f(int&, int);
int main()
{
 int N, s;
 cout << "how many? ";
 cin >> N;
 f(N, s);
 cout << "The result = " << (double) s / N << endl;
 return 0;
}
void f(int &n, int s)
{
 int m;
 cout << "enter " << n << " integers:- " << endl;
 for (; n > 0; n--) {
cin >> m;
s = s + m;
 }
}





我的尝试:



仔细阅读下面列出的程序。该程序包含错误。

(i)正确识别错误,描述错误并在答案中解释其原因。
请注意,错误识别错误将导致减少你的分数。

(15分)

(ii)对程序进行少量更改以纠正这些错误。将

更正的程序保存到此问题的指定文件夹中。

(10分)



What I have tried:

Read through the program listed below carefully. The program contains errors.
(i) Correctly identify the errors, describe them and explain their causes in the answer book.
Be aware that identifying errors incorrectly will result in reduction of your marks.
(15 marks)
(ii) Make minimal amount of changes to the program to correct these errors. Save the
corrected program into the designated folder for this question.
(10 marks)

推荐答案

您好会员13246826,



因为这是你的功课,你需要考虑一下。我看到了问题,但我不应该告诉你解决方案。



但是,我可以给你一个提示 - 阅读有关按值传递参数,并传递参数的方法参考。我希望你能找到答案并根据需要更正代码。
Hi Member 13246826,

As this is your homework, you need to think about it. I see the problem but I should not be telling you the solution.

However, I can give you a hint - read about passing parameter by value, and passing parameter by reference. I hope you will find the answer and correct the code as needed.


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

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