Thread: i have a problem in my program that iam not able to solve

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    5

    i have a problem in my program that iam not able to solve

    Code:
    // final.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int call_box(int a[8][8],int box){
    	if(box>=1&&box<=8){
    		int i=0;
    		int j=box-1;
    			return a[i][j];}
    	if(box>=9&&box<=16){
    	int i=1;
    	int j=box-9;
    	return a[i][j];}
    	if(box>=17&&box<=24){
    		int i=2;
    		
    		int j=box-17;
    	return a[i][j];
    	}
    	if(box>=25&&box<=32){
    		int i=3;
    		
    	int j=box-25;
    	return a[i][j];
    	}
    	if(box>=33&&box<=40){
    		int i=4;
    		
    	int j=box-33;
    	return a[i][j];
    	}
    	if(box>=41&&box<=48){
    		int i=5;
    		
    	int j=box-41;
    	return a[i][j];
    	}
    	if(box>49&&box<=56){
    		int i=6;
    		
    	int j=box-49;
    	return a[i][j];
    	}
    	if(box>=57&&box<=64){
    		int i=7;
    		
    	int j=box-57;
    	return a[i][j];
    	}
    }
    
    int call_boxf(int l[8][8],int box){
    	if(box>=1&&box<=8){
    		int i=0;
    		int j=box;
    			return l[i][j];}
    	if(box>=9&&box<=16){
    	int i=1;
    	int j=box-9;
    	return l[i][j];}
    	if(box>=17&&box<=24){
    		int i=2;
    		
    		int j=box-17;
    	return l[i][j];
    	}
    	if(box>=25&&box<=32){
    		int i=3;
    		
    	int j=box-25;
    	return l[i][j];
    	}
    	if(box>=33&&box<=40){
    		int i=4;
    		
    	int j=box-33;
    	return l[i][j];
    	}
    	if(box>=41&&box<=48){
    		int i=5;
    		
    	int j=box-41;
    	return l[i][j];
    	}
    	if(box>49&&box<=56){
    		int i=6;
    		
    	int j=box-49;
    	return l[i][j];
    	}
    	if(box>=57&&box<=64){
    		int i=7;
    		
    	int j=box-57;
    	return l[i][j];
    	}
    }
    
    
    int check_and_copy(int a[8][8],int l[8][8], int final[8][8]){
    	cout<<"enter the number of each square by pressing enter after each square number";
    		int box1;
    		int box2;
    		int count=0;
    		int countg=0;
    	while(count<32){
    		
    		cin>>box1;
    		cin>>box2;
    		if(box1>=1&&box1<=64&&box2>=1&&box2<=64)
    		call_box(a,box1);
    		call_box(a,box2);
    		if(call_box(a,box1)==call_box(a,box2)){
    			if(call_box(a,box1)!=call_boxf(final,box1)){
    
    				call_boxf(final,box1)=call_box(a,box1);
    			call_boxf(final,box2)=call_box(a,box2);
    			count++;
    			cout<<"your answer is right enter another one";}
    			else{cout<<"you already gave this answer";}
    		}else{ cout<<"your answer is wrong try again";}
    		else{ cout<<"you answer is out of bound try again";}
    		for(int i=0;i<7;i++){
    		for(int j=0;j<7;j++){
    			cout<<l[i][j]<<"  ";}cout<<endl;}
    		cout<<countg;}
    	
    		return final[8][8];}
    void assign_half(int a[8][8],int r, int c){
    	for(int i=0;i<4;i++){
    		for(int j=0;j<8;j++){
    			a[i][j]=rand()%100;
    	}
    	}
    }
    void double_of_each(int a[8][8],int r,int c){
    	int maxr=4;
    	
    	for(int i=0;i<4;i++){
    		int maxc=7;
    		for(int j=0;j<8;j++){
    			a[maxr][maxc]=a[i][j];
    			maxc--;
    		}
    		maxr++;}
    }
    
    int assignl(int l[8][8],int r,int c){
    	int f=1;
    	for(int b=0;b<8;b++){
    		for(int c=0;c<8;c++){
    			l[b][c]=f;
    			f++;
    				
    	}}
    	return l[8][8];
    }
    void disp(int l[8][8],int r,int c){
    	for(int i=0;i<r;i++){
    		for(int j=0;j<c;j++){
    				cout<<l[i][j]<<"  ";
    		}
    		cout<<endl;
    	}
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int a[8][8]={0};
    	int f[8][8]={0};
    	int l[8][8]={0};
    	int r=8;
    	int c=8;
    	assignl(l,r,c);
    	disp(l,r,c);
    	assign_half(a,r,c);
    	double_of_each(a,r,c);
    	check_and_copy(a,l,f);
    	getch();
    	return 0;
    }
    the error is in these lines
    call_boxf(final,box1)=call_box(a,box1);
    call_boxf(final,box2)=call_box(a,box2);

    error C2106: '=' : left operand must be l-value
    Last edited by Salem; 04-12-2011 at 12:59 PM. Reason: added [code][/code] tags - learn to use them yourself

  2. #2
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    What the hell is it supposed to do?
    I will be damn impressed if some other programmer can tell me?
    You ended that sentence with a preposition...Bastard!

  3. #3
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    well one reason is probably because you are not returning a value from call_box and that call_boxf is not a reference.. so cannot store values like a variable can...they're rvalues
    a = 19 ; a is a lvalue, 19 is a rvalue
    so it is telling you that call_boxf(f,b) is an lvalue, you can return a value from the function and store in a variable..try returning a reference from call_boxf..but bad practice.
    Last edited by Eman; 04-12-2011 at 02:46 PM.
    You ended that sentence with a preposition...Bastard!

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Eman View Post
    ...a = 19 ; a is a rvalue, 19 is a lvalue...
    It's the other way around.
    Variables tend to appear on the left-hand side of an assignment and they're assignable.
    However, constants, function calls and temporaries and right-hand side values since they're not assignable.
    (Okay, that's probably not entirely right; but think of it as a simplified model.)

    In any case, what you did was basically try to assign a temporary to a temporary, which isn't allowed.
    What are you trying to do?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    oops..didn't see that.
    Thanks
    You ended that sentence with a preposition...Bastard!

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    5

    what iam trying to do

    is the assign the returned value by the call_box to the the returned value of call_boxf
    and it is not working

  7. #7
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    yes, because you can't assign an rvalue to another rvalue, or a temp to another temp.
    You ended that sentence with a preposition...Bastard!

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, but WHY are you doing that?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-14-2008, 06:17 PM
  2. [NEED HELP] I just can't solve this program problem!
    By frodonet in forum C Programming
    Replies: 7
    Last Post: 09-23-2007, 02:44 PM
  3. can u solve this program :P
    By bawen in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2006, 12:16 PM
  4. Replies: 2
    Last Post: 12-19-2005, 06:57 PM
  5. Replies: 2
    Last Post: 04-25-2005, 11:59 AM