CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Arrays! I'm trying to get my code to work but its not compling!

    Hi there im basically trying to create a 3 x 3 grid guessing game where the user has to guess what the number is behind the '?' between 1-9. They have got a maxinum of 20 goes, I've created some if staements i've pretty much finished it now but i was wondering if anyone would check it just because at the moment i cant get it to work it would be greatly appreshiated!

    Code:
    #include<iostream>
    #include<conio.h>
    #include<string>
    #include<cstdlib>
    #include<ctime>
    
    using namespace std;
    
    int pause()						//Funtion for pause
    {
    	int in;
    	scanf("%c",&ch);			
    	getint();					
    	return 0;
    }
    
    int main ()
    {
       int Go= 1, numbers_ctr=0; 
       
    	cout<< "Welcome to Guess Game" <<endl; //I'm inserting a message so that when the game loads the user will be welcomed into the game.
    
    
    //This is the Character Array	
     char coveredarray [3][3] =      {{'?','?','?'},	                          
                                    {'?','?','?'},
                                    {'?','?','?'}};
                                    
                                    
        for(int row = 0; row < 3; row++)
        {
            for(int column = 0; column < 3; column++)
            {
                cout << coveredarray[row][column] << " ";
    
    		}
                cout << endl;
            }
    //This is the Guess Array
    
    	int randarray[3][3] = {{0,0,0},
    	                       {0,0,0},
    	                       {0,0,0}};
    
        srand(unsigned time(0));
        
        int randarray[3][3] = rand()%9 + 1;
        
        for(int row = 0; row < 3; row++)
    	{
              { for(int column = 0; column < 3; column++)
                   { cout <<  randarray[row][column];
    	}
    }
    
    }
    	int playarray[3][3]; 
    
    	 int row, column;
    	 int turn= 1, mine_ctr=0; 
    	 int play_row, play_column;
    
    int row , column;  // Spelling of column is incorrect 
    cout << "Please enter the row to enter a number between 1-3 " << endl;
    cin >> row;
    
    if (playarray[column] [row] != 0 )
    
    {
    	playarray[row][column] = 0 ; //If you get the number wrong then it will appear as a 0
    	{
    cout<<endl;
    cout<< "Go"<<endl;
    cout<< "Wrong number:"<<numbers_ctr<<" "<<"Please enter another number"<< <<endl;
    }
    while (Go < 21) 
    {
    cout<<endl;
    cout<< "Go"<<endl;
    cout<< "Numbers found:"<<numbers_ctr<<" "<<"Numbers yet to be found:"<<10 - numbers_ctr<<endl;
    }
    
    if((play_row < 1) || (play_row > 3))
    {
    cout<<endl;
    cout<< "Go"<<endl;
    cout<< "Remember, choose between 1 - 3"<<endl; //This will stop the user entering numbers larger than the grid
    system("pause");
    continue;
    {
    
    if((play_column < 1) || (play_column > 3)
    {
    cout<<endl;
    cout<< "Go"<<endl;
    cout << "Please enter the column to enter a number between 1-3" << endl;
    cin >> column;
    {
    
    if (playarray[column] [row] =<9)
    {
    cout<<endl;
    cout<< "Go"<<endl;
    cout<< "Remember, choose between 1 - 9"<<endl; //This will stop the user entering numbers larger than the grid
    system("pause");
    continue;
    {
    
    
    cin >> num[row-1][column-1];
    }
    
    {
    if (randarray[row][column] =<9) ; // The number will change if you get the right answer
    {
    cout<< "Go"<<endl;
    cout<<"Please enter a number between 1-9 "<<endl; cout<< "Number Found"<<endl;
    playarray[play_row-1][play_column-1] = ; 
    numbers_ctr++;
    for (int row=0; row<3; row++)
    {
    for(int column=0; column<3; column++)
    {
    cout<<playarray[row][column]<<" ";
    }
    cout<<endl;
    
    }
    
    else
    //This will show an F to show the flagged area the user has been before
    {
    cout<<" Please Try again "<<endl;
    playarray[play_row-1][play_column-1] = 0;
    }
    for(int row=0; row <3; row++)
    }
    for(int column=0; column<3; column++)
    {
    cout<<playarray[row][column]<<" ";
    }
    cout<<endl;
    
    {
    } while (Go < 21) 
    {
    
    cout<<endl;
    cout<< "Numbers found:"<<numbers_ctr<<" "<<"Numbers yet to be found:"<<10 - numbers_ctr<<endl;
    numbers_ctr<<endl;
    
    {
    if (playarray[column] [row] != 0 )
    {
    cout<<endl;
    cout<< "Go"<<endl;
    cout<<" Wrong Number "<<endl;:"<<numbers_ctr<< << "Please enter another number" << <<endl;
    
    playarray[play_row-1][play_column-1] = 'F';
    
    for(int row=0; row <3; row++)
    
    {
    for(int column=0; column<3; column++)
    {
    cout<<playarray[row][column]<<" ";
    }
    cout<<endl;
    
    
    
    if(playarray[play_row-1][play_column-1] == 1)
    
    {
    cout<< "Go"<<endl;
    cout<<" That position has already been selected please choose another row and column "<<endl;
    system("pause");
    continue;
    }
    array[play_row-1][play_column-1]=1;
    
    
    if(numbers_ctr == 9)
    
    {
    cout<<" You have won "<<endl;
    break;
    }
    
    Go++;
    
    
    }   
    } 
    if(Go==21)
    
    {
    cout<<" You have reached your number of goes. "<<endl;
    }
    
    _getch();
    
    
    }

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Arrays! I'm trying to get my code to work but its not compling!

    Yes, you have rather a large number of compile errors. Most of these are fairly obvious from the error description and the referred line (eg using variable ch in scanf when ch hasn't been defined and using function getint() which also hasn't been defined. A couple might require further comment. Its <= in comparison tests, not =<. A continue statement can only be used within a loop (for, do or while) - not within an if/else structure.

    Might I suggest for future that instead of trying to code the whole program at once and then finding a large number of compile errors, you code it in sections from your program design, and compile after each section is coded (eg after each function etc) and deal with any compile errors. That way at least you have only (hopefully) a small number of compile errors with which to deal at once.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured