Thread: Scope problem

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    51

    Scope problem

    I created a function and declared int x=0; at the very top. then later on x is in a nested for loop but for some reason the x isn't being changed as if I had another x in the local scope.

    Code:
    x=0;
    	for(count=0; count<3; count++){
    
    		for(int N=start; N==start+24; N++){
    			Accounts->Name[N]=buff[N];
    			x++;
    		}
    		x+=3;
    		cout<<x<<endl;
    
    		for(z=x; z==start+28; z++){
    			A[z]=buff[z];
    			cout<<A[z]<<endl;
    			if(z==4){
    				Accounts->Acc_Number=atoi(A);
    				cout<<'\t'<<Accounts->Acc_Number;
    			}
    		}
    		x+=3;
    
    		for(int r=z; r==start+45; r++){
    			Accounts->Acc_Balance=buff[x];
    			start=r;
    		}
    		Accounts++;
    	}

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Your loops will never run. A for loop only runs while the middle expression evaluates to true. But, for example, if you initialize N to start, it cannot be true that N == start+24.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Binary Search Tree scope? problem
    By tms43 in forum C++ Programming
    Replies: 5
    Last Post: 11-01-2006, 10:13 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM