如何解决此编码问题? [英] How do I fix this coding problem?

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

问题描述

我已经尝试过并试图找出此代码中的错误,但没有任何工作,有人可以帮忙吗?代码低于。



I have tried and tried to figure out what is wrong in this code and nothing is working, can someone please help? the code is down below.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	//declare array
	double scores[5][3] = {{75.5, 80.5, 0.0}, 
						   {88.5, 89.5, 0.0},
	 					   {63.0, 54.0, 0.0}, 
						   {100.0, 99.0, 0.0}, 
						   {88.5, 88.5, 0.0}};
  
	//calculate and assign average
	for (int row = 0; row < 5; row += 1)
		scores[row][0] = scores[row][0] + scores[row][1] / 2;
	//end for

	//display averages stored in the array
	cout << fixed << setprecision(1);
	for (int row = 0; row < 5; row += 1)
		cout << "Student " << row + 1 << " average: " 
			<< scores[row][2] << endl;
	//end for

	//system("pause");
    return 0;
}   //end of main function





我尝试了什么:



我已经尝试了几次修改来调试这段代码,但没有正在工作。



What I have tried:

Ive tried several corrections to debug this code but nothing is working.

推荐答案

显然,你自己的代码对你来说就像一个黑盒子。它不符合你的期望,你不明白为什么。

以下内容不是直接解决你的问题,而是一个能帮助你自己理解错误的关键。

调试器是你的朋友。它将向您显示您的代码实际正在做什么。

按照执行,检查变量,您将看到有一个点,它停止做您期望的。

掌握Visual Studio 2010中的调试 - 初学者指南 [< a href =http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-A-Beginntarget =_ blanktitle =New Window> ^ ]

调试器 - 维基百科,免费的百科全书 [ ^ ]



注意:

- 你计算平均值,你在哪里保存它?

- 你显示平均值,它来自哪里?

- 它是否匹配?



- 检查你如何计算平均值。

Obviously, your own code is like a blackbox to you. It don't do what you expect, and you don't understand why.
What follow is not directly a solution to your problem, but a key that will help you to understand by yourself what is wrong.
The debugger is your friend. It will show you what your code is really doing.
Follow the execution, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Debugger - Wikipedia, the free encyclopedia[^]

Pay attention to :
- you calculate the "average", where do you save it ?
- you display an "average", where does it come from ?
- does it match ?

-Check how you calculate the average.
引用:

我已经尝试了几次修改来调试这段代码,但没有任何工作。

I've tried several corrections to debug this code but nothing is working.



永远不要尝试随机修正,看它是否有效,它是浪费时间,最好使用调试器并将你看到的内容与你期望的内容进行比较。


Never try random corrections to see if it work, it is a waste of time, it is better to use a debugger and compare what you see with what you expect.


//calculate and assign average
	for (int row = 0; row < 5; row += 1)
		scores[row][0] = scores[row][0] + scores[row][1] / 2;
	//end for



您将结果存储在单元格[0]而不是单元格[2]中,这是用于显示答案的单元格。


You are storing the result in cell[0] instead of cell[2], which is the one you use to display the answers.


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

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