[try Beta version]
Not logged in

 
global variable !!!

Nov 26, 2013 at 4:22pm
Hi everybody , I wonder how I can deal with such error , especially in while loop ???


{ class/struct/union
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(100): error C2065: 'Q' : undeclared identifier
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(101): error C2065: 'index' : undeclared identifier
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(101): error C2228: left of '.name' must have class/struct/union
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(106): error C2065: 'first' : undeclared identifier
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(106): error C2065: 'index' : undeclared identifier
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(108): error C2065: 'index' : undeclared identifier
1>c:\users\m..s\documents\visual studio 2010\projects\project - initial\project - initial\hash.cpp(109): error C2065: 'index' : undeclared identifier
}


bool WZhash::insert(){
int I, char * name , double C , int Q , index , K , first ;
/*
inserting a certain commodity with it's name , Id , cost and Quantity .
*/

cout<<"please insert the Id , name , cost and the quantity if the commodity respectively \n " ;
cout<<"Id :\n";
cin>>I ;
cout<<"Name : \n";
cin>>name;
cout<<"Cost :\n";
cin>>C;
cout<<"Quantity :\n";
cin>>Q;

////////////////////////////
K = I % size ;
index = Universal(K);
if(A[index].cost == -1 ){//////means it's empty
A[index].id = I;
A[index].cost = C;
A[index].quan = Q ;
strcpy(A[index].name , name) ;
return true ;
}
else{

first = index ;
int j = 1 ;
index += 1 ;
while ((A[index].cost != -1 ) && ( index != first ) ){

index = index + ( j * j ) ;
if(A[index].cost == -1 ){

A[index].id = I;
A[index].cost = C;
A[index].quan = Q ;
strcpy(A[index].name , name) ;
return true ;
}
else {
j++ ;
continue ;
}
}
}
if(index == first ){ cout<<"I'm very sorry , no space , or potential duplicate might exist \n "; return false ; }
}

Nov 26, 2013 at 4:27pm
int I, char * name , double C , int Q , index , K , first ;

you don't declare different datatypes on one line like that.

listen to your compiler. it's even giving you the line to look at.
Nov 26, 2013 at 4:51pm
but , i don't know what to do , it does not always help me
Nov 26, 2013 at 4:57pm
int I, char * name , double C , int Q , index , K , first ;

have a separate line for each of these to start with.
Nov 26, 2013 at 4:58pm
Here is the important part of the error log:

Q' : undeclared identifier
- This shows there is an issue with the declaration of 'Q'.

A tip is that the error is usually on the same line were the error is found (but not always).

If you click the error it usually jumps to where the error is in the program.

---------------------------------------------------------------------------------------
When you declare variables of different type, then they need to be on a separate line and each line has to end with a ;

For example

1
2
3
int x, y, z;//this declares 3 variables of type int with the names x, y & z
char a, b, c;//this declares 3 variables of type char with the names a, b & c
float myFloat;//this declares a variable of type float, with the name myFloat 


If you are declaring more than one variable of the same type on the same line, then you need to use a ',' between each variable name.
Last edited on Nov 26, 2013 at 5:03pm
Topic archived. No new replies allowed.