2 Replies - 804 Views - Last Post: 19 December 2010 - 11:22 AM Rate Topic: -----

#1 MAbebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-December 10

Undeclared Identifier error message

Posted 19 December 2010 - 11:02 AM

Hello everyone,

I am a kind of still learning about C++ and I just have some kind of error message on my code telling me that undeclared identifier error code c2065. I am trying to figure out where my error is and how to fix it. I kind of know what my error but, I just don't know how to fix it. Thanks for the help.

Here is my code
#include <iostream>


typedef struct NodeType {
	char name;		// the node's name
	int weight;		// the node's current weight
	int pi;			// the node's parent
} Node;

int graph[6][6] = {
	{0,1,2,0,0,0},
	{1,0,5,9,0,10},
	{2,5,0,3,0,0},
	{0,9,3,0,3,0},
	{0,0,0,3,0,2},
	{0,10,0,0,2,0}
};

Node node[6];
bool visited[6];

int getMinNode() 
{
	int index = -1;
	for (int i=0; i<6; i++) 
	{
		if (!visited[i]) 
		{
			index = i;
			break;
		}
	}
	
	for (int j=i+1; j<6; j++)
	{
		if (node[j].weight < node[index].weight) index = j;
	}
	return index;
}

void printResult(char *message) {
	printf("%s\n", message);
	for (int i=0; i<6; i++) {
		if (node[i].pi >= 0) {
			int parent = node[i].pi;
			printf("%c -- %c \n", node[i].name, node[parent].name);
		}
	}
}

int main() {	// Prim's algorithm
	
	// Initialize the 6 nodes
	for (int i=0; i<6; i++) {
		node[i].name = 'A'+i;
		node[i].pi = -1;		// no parent
		node[i].weight = 10000;	// 10000 as infinity
		visited[i] = false;
	}
	// Start from node 'A'
	node[0].weight = 0;
	int index = getMinNode();

	// Prim's algorithm
	while (index >= 0) {
		visited[index] = true;
		for (int j=0; j<6; j++) {
			if (j==index) continue;
			if (graph[j][index] == 0) continue;
			int weight = node[index].weight + graph[j][index];
			if (weight < node[j].weight) {
				node[j].weight = weight;
				node[j].pi = index;
			}
		}
		index = getMinNode();
	}
	
	// Print out the result
	printResult("Final Minimum Spanning Tree:");
}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

Also, post in the RIGHT forum...Site Feedback is NOT for C++ Questions. Moved to C and C++.

This post has been edited by JackOfAllTrades: 19 December 2010 - 11:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Undeclared Identifier error message

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1530
  • View blog
  • Posts: 5,518
  • Joined: 03-August 09

Re: Undeclared Identifier error message

Posted 19 December 2010 - 11:20 AM

give us the exact error message. i don't feel like sifting though you code figuring out what line the error occurred on and what identifier it's talking about. maybe someone with a keen eye can help you real quick but im going to ask for the error message.

edit:
@ButchDean: looks like you the keen eye the OP was hoping for ;)

This post has been edited by ishkabible: 19 December 2010 - 11:28 AM

Was This Post Helpful? 0
  • +
  • -

#3 ButchDean  Icon User is offline

  • Ex-Pro Games Programmer
  • member icon


Reputation: 876
  • View blog
  • Posts: 3,343
  • Joined: 26-November 10

Re: Undeclared Identifier error message

Posted 19 December 2010 - 11:22 AM

your declaration for 'i' on line 25 fell out of scope when the for loop terminated. Does that help any? :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1