neww prob

This is a discussion on neww prob within the C++ Programming forums, part of the General Programming Boards category; Code: // final.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <conio.h> #include ...

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

    neww prob

    Code:
    // final.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    #include <ctype.h>
    using namespace std;
    int call_boxi(int a[8][8],int box){
    	if(box>=1&&box<=8){
    		int i=0;
    		return i;}
    	if(box>=9&&box<=16){
    	int i=1;
    	return i;}
    	if(box>=17&&box<=24){
    		int i=2;
    	return i;
    	}
    	if(box>=25&&box<=32){
    		int i=3;
    	return i;
    	}
    	if(box>=33&&box<=40){
    		int i=4;
    	return i;
    	}
    	if(box>=41&&box<=48){
    		int i=5;
    	return i;
    	}
    	if(box>49&&box<=56){
    		int i=6;
    	return i;
    	}
    	if(box>=57&&box<=64){
    		int i=7;
    	return i;
    	}
    }
    
    int call_boxj(int l[8][8],int box){
    	if(box>=1&&box<=8){
    		int j=box-1;
    			return j;}
    	if(box>=9&&box<=16){
    	int j=box-9;
    	return j;}
    	if(box>=17&&box<=24){
    		int j=box-17;
    	return j;
    	}
    	if(box>=25&&box<=32){
    	int j=box-25;
    	return j;
    	}
    	if(box>=33&&box<=40){
    	int j=box-33;
    	return j;
    	}
    	if(box>=41&&box<=48){
    	int j=box-41;
    	return j;
    	}
    	if(box>49&&box<=56){
    	int j=box-49;
    	return j;
    	}
    	if(box>=57&&box<=64){
    	int j=box-57;
    	return j;
    	}
    }
    int call_boxy(int l[8][8],int box){
    	if(box>=1&&box<=8){
    		int j=box-1;
    			return j;}
    	if(box>=9&&box<=16){
    	int y=box-9;
    	return y;}
    	if(box>=17&&box<=24){
    		int y=box-17;
    	return y;
    	}
    	if(box>=25&&box<=32){
    	int y=box-25;
    	return y;
    	}
    	if(box>=33&&box<=40){
    	int y=box-33;
    	return y;
    	}
    	if(box>=41&&box<=48){
    	int y=box-41;
    	return y;
    	}
    	if(box>49&&box<=56){
    	int y=box-49;
    	return y;
    	}
    	if(box>=57&&box<=64){
    	int y=box-57;
    	return y;
    	}
    }
    int call_boxx(int a[8][8],int box){
    	if(box>=1&&box<=8){
    		int x=0;
    		return x;}
    	if(box>=9&&box<=16){
    	int x=1;
    	return x;}
    	if(box>=17&&box<=24){
    		int x=2;
    	return x;
    	}
    	if(box>=25&&box<=32){
    		int x=3;
    	return x;
    	}
    	if(box>=33&&box<=40){
    		int x=4;
    	return x;
    	}
    	if(box>=41&&box<=48){
    		int x=5;
    	return x;
    	}
    	if(box>49&&box<=56){
    		int x=6;
    	return x;
    	}
    	if(box>=57&&box<=64){
    		int x=7;
    	return x;
    	}
    }
    
    
    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"<<endl;
    		int box1;
    		int box2;
    		int count=0;
    		int countg=0;
    	while(count<32){
    		
    		cin>>box1;
    		cin>>box2;
    		int i=0;
    		if(box1>=1&&box1<=64&&box2>=1&&box2<=64){
    		int i=call_boxi(a,box1);
    		int j=call_boxj(a,box2);
    		int x=call_boxx(a,box1);
    		int y=call_boxy(a,box2);
    		if(a[i][j]==a[x][y]){
    			if(a[i][j]!=final[i][j]){
    				final[i][j]=a[i][j];
    				final[x][y]=a[x][y];
    			count++;
    			cout<<"your answer is right enter another one"<<endl;}}
    			else{if(a[i][j]==final[i][j]||a[x][y]==final[x][y]){
    				cout<<"you already gave this answer"<<endl;}}
    			else{ if(a[i][j]!=a[x][y]){
    				cout<<"your answer is wrong try again"<<endl;}}}
    		else{ cout<<"your answer is out of bound try again"<<endl;}
    		
    		countg++;
    		for(int i=0;i<8;i++){
    		for(int j=0;j<8;j++){
    			cout<<l[i][j]<<"  ";}cout<<endl;}
    		
    		cout<<"# of right answers is"<<count<<endl;
    		cout<<"# of total gusses is "<<countg<<endl;}
    	
    		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;
    }
    in this program countg is not being incremented and count is not being displayed
    and also the last else in the check_and_copy function is not matched to the first if how can i solve it

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,698
    in this program countg is not being incremented and count is not being displayed
    That is quite understandable since this code does not compile. You may want to look at your error/warning messages. Here is what I get:

    main.cpp||In function ‘int check_and_copy(int (*)[8], int (*)[8], int (*)[8])’:|
    main.cpp|160|warning: declaration of ‘i’ shadows a previous local|
    main.cpp|158|warning: shadowed declaration is here|
    main.cpp|177|error: expected ‘}’ before ‘else’|
    main.cpp|178|error: ‘j’ was not declared in this scope|
    main.cpp|178|error: ‘x’ was not declared in this scope|
    main.cpp|178|error: ‘y’ was not declared in this scope|
    main.cpp|183|error: ‘else’ without a previous ‘if’|
    main.cpp|197|warning: no return statement in function returning non-void|
    main.cpp|199|error: expected unqualified-id before ‘return’|
    main.cpp|200|error: expected declaration before ‘}’ token|
    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lil prob
    By psycho88 in forum C Programming
    Replies: 7
    Last Post: 12-01-2005, 11:04 AM
  2. not sure what the prob is
    By Rykaerdoe in forum C Programming
    Replies: 2
    Last Post: 12-01-2004, 01:09 PM
  3. Prob
    By Ajsan in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2004, 11:24 AM
  4. IE6.0 Prob
    By valar_king in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 12-02-2002, 08:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21