我有问题吗? [英] i have problem with pert ?

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

问题描述

我希望该程序完成这项工作:
我有矩阵0 1 5
0 0 7
0 0 0
我希望这个矩阵做程序评估和审查技术的代码(PERT)
int表示a [0] [1] + a [1] [2];
但这不行吗?

i want that this program do this work :
i have matrix 0 1 5
0 0 7
0 0 0
i want that this matrix do the code for Program evaluation and review technique(PERT)
int means a[0][1]+a[1][2];
but it doesn''t do ?

// control proje2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main()
{
	int t[100][100] ;
	int n ;
	int i , j ;
	int s = 0 ;

	cout << "enter the n " << endl ;
	cin >> n ;

	for( i = 0 ; i < n ; i++ )
	{
		for( j = 0 ; j < n ; j++ )
		{
			cin >> t[i][j] ;
		}
	}

	if( t[i][j] != 0 )
	{ 
		
		for( i = 0 ; i < n ; i++ )
		{
			for( j = 0 ; j < n ; j++ )
			{
				cout << "yay" << t[i][j] << endl ;
				s += t[i][j] ;
				cout << "(" << i << "," << j << ")" << s << endl ;
			}
		}
		
	}
	int a[100];
	int x=0;
		for( i = 0 ; i < n ; i++ )
		{
			for( j = 0 ; j < n ; j++ )
			{
				if( j != 0 )
				{
					a[x] = t[i][j]+t[j][i];
					cout << "("<< i<<","<<j<<")"<<a[x];
				}
			}
		}
	
		//int max ;
		//for(int i = 0 ; i < n ; i++)
		//{
		//	max = 0 ;
		//}
		//for (j = 0; j < n; j++)
		//{
		//   if (t[i, j] == 0)
		//   {
		//    //flag = 1;
		//   }
		//else
		//{
		////flag = 0;
		//if (t[0][j] > max)
		//max = t[0][j];
		//}
		//}

	//if( i != 0 && j != 0 )
	//{
	//	s += t[i][j] ;
	//	//cout << t[i][j] ;
	//}
	 return s ;


	return 0;
}

推荐答案

在第一个循环之后,您需要执行以下操作
Following the first loop you have the line
if( t[i][j] != 0 )


这是错误的,因为ij现在都将等于n的值,从而寻址超出数组限制的元素;简单地说,您正在访问一个未初始化的变量.至于其余的,我没有详细介绍,但是您可能有类似的问题.另外,您的评论没有做并不能真正帮助任何人尝试找出您做错了什么.

最好在程序运行时打印一些中间值,或者与调试器一起逐步检查中间值,以了解发生了什么.


which is wrong, since both i and j will now be equal to the value of n and thus addressing an element beyond the limits of your arrays; simply put you are accessing an uninitialised variable. As to the rest, I have not gone through it in detail but you may have similar issues. Also your comment it doesn''t do does not really help anyone to try and figure out what you are doing wrong.

It may be better for you to print some of your intermediate values as your program runs, or step through it with the debugger to see what is happening.


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

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