Thread: Game of Nim (PROJECT HELP!)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You need to still track how many sticks are left with the variable sum, so:

    Code:
    #include <stdio.h>
    
    int main ()
    {
        int rows[] = { 2, 4, 6};
        int i, j,sum;
        
        sum=rows[0]+rows[1]+rows[2];
        while(sum>0) {
           printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");
    
           for(i = 0; i < 3,; i++)
           {
              printf("\nRow %d:", i+1);
    
              for(j = 0; j < rows[i] ; j++)
              {
                    printf("\t|");
              }
    
              printf("\t|");
           }
           
           //ask the user what row they want to pick sticks from
           scanf() to get that number. (an int rowChosen)
    
           //ask the user how many sticks they want to remove
           scanf() to get that number. (an int sticksChosen)
    
           rows[rowChosen+1] -= sticksChosen;
           sum -= sticksChosen;
       }
        return 0;
    }
    And so on. Add in your player code, etc.

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by Adak View Post
    You need to still track how many sticks are left with the variable sum, so:

    Code:
    #include <stdio.h>
    
    int main ()
    {
        int rows[] = { 2, 4, 6};
        int i, j,sum;
        
        sum=rows[0]+rows[1]+rows[2];
        while(sum>0) {
           printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");
    
           for(i = 0; i < 3,; i++)
           {
              printf("\nRow %d:", i+1);
    
              for(j = 0; j < rows[i] ; j++)
              {
                    printf("\t|");
              }
    
              printf("\t|");
           }
           
           //ask the user what row they want to pick sticks from
           scanf() to get that number. (an int rowChosen)
    
           //ask the user how many sticks they want to remove
           scanf() to get that number. (an int sticksChosen)
    
           rows[rowChosen+1] -= sticksChosen;
           sum -= sticksChosen;
       }
        return 0;
    }
    And so on. Add in your player code, etc.
    Okie dude let me try it.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by Adak View Post
    You need to still track how many sticks are left with the variable sum, so:

    Code:
    #include <stdio.h>
    
    int main ()
    {
        int rows[] = { 2, 4, 6};
        int i, j,sum;
        
        sum=rows[0]+rows[1]+rows[2];
        while(sum>0) {
           printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");
    
           for(i = 0; i < 3,; i++)
           {
              printf("\nRow %d:", i+1);
    
              for(j = 0; j < rows[i] ; j++)
              {
                    printf("\t|");
              }
    
              printf("\t|");
           }
           
           //ask the user what row they want to pick sticks from
           scanf() to get that number. (an int rowChosen)
    
           //ask the user how many sticks they want to remove
           scanf() to get that number. (an int sticksChosen)
    
           rows[rowChosen+1] -= sticksChosen;
           sum -= sticksChosen;
       }
        return 0;
    }
    And so on. Add in your player code, etc.

    Code:
    printf("Please Enter a Row: ");
        scanf("%d", rowChosen);
        printf("Please Enter how many stick you will get: ");
        scanf("$d", sticksChosen);
    
        rows[rowChosen+1] -= sticksChosen;
        sum -= sticksChosen
    Is this right? or cause it has error expected ';'

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Code:
    #include <stdio.h>
    
    int main ()
    {
        int rows[] = { 2, 4, 6}; //Printing Game board
        int i, j; // Variable in Printing Gameboard
        int player =1; //The players
        int rowChosen, sticksChosen; //Scan purpose
        int sum;
    
    
    
        printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");
    
    
    
        for(i = 0; i < 3; i++)
            {
              printf("\nRow %d:", i+1);
    
                for(j = 0; j < rows[i] ; j++)
                {
                    printf("\t|");
                }
    
              printf("\t|");
            }
    
              printf("\n");
    
        printf("Please Enter a Row: ");
        scanf("%d", rowChosen);
        printf("Please Enter how many stick you will get: ");
        scanf("$d", sticksChosen);
    
            rows[rowChosen+1] -= sticksChosen;
            sum -= sticksChosen;
    
        return 0;
    }
    It runs now but when i enter a row number the program will be shut down..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ and SDL amateur looking for a game project.
    By traitor_651 in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-15-2010, 11:16 AM
  2. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  3. Little game project
    By Gen. in forum Projects and Job Recruitment
    Replies: 7
    Last Post: 08-19-2006, 10:29 PM
  4. 2D Game Project with DirectX and C++
    By VMJC in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 12-23-2004, 12:28 AM
  5. new game project need help
    By L_I_Programmer in forum Game Programming
    Replies: 1
    Last Post: 03-15-2003, 09:41 PM