Thread: Help for our project

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    59

    Post Help for our project

    We are given a project that could GAME OF NIM with this problem
    there only have 3 rows and the first row will have 3 and second will have 5 and third will have 7 and it will be played by two player (HUMAN) and my problem here in our code is it never declared a winner. CAN ANYONE HELP PLEASE.

    Code:
    #include <stdio.h>
            main()
            {
            int row1[3]={1,1,1};
            int row2[5]={1,1,1,1,1};
            int row3[7]={1,1,1,1,1,1,1};
            int j; int i=1;
            int item; int l;
            int row; int player=1;
            int column; int sum;
    
    
    
            while (i<sum)
            {
            printf("\nPlayer %d's turn! \n\n",player);
            player++;
            if(player == 3)
            player = player - 2;
    
    
            printf("\tRow 1: %d %d %d\n",row1[0],row1[1],row1[2]);
            printf("\tRow 2: %d %d %d %d %d\n", row2[0],row2[1],row2[2],row2[3],row2[4]);
            printf("\tRow 3: %d %d %d %d %d %d %d\n",row3[0],row3[1],row3[2],row3[3],row3[4],row3[5],row3[6]);
    
            printf("\nEnter row number: ");
            scanf("%d", &row);
            if(row > 3 || row < 1)
            {
            printf("Error! Enter number from 1-3!\n");
    
            while (row > 3|| row < 1)
            {printf("Enter row number: ");
            scanf("%d", &row);}
            }
            printf("Enter number of items to remove: ");
            scanf("%d", &item);
    
            switch(row)
            {
            case 1:
            {
            if(item>3||item<1)
            printf("Error! Enter number from 1-3!\n");
            while(item>3||item<1)
            {printf("Enter number of items to remove:");
            scanf("%d", &item);}
            }
            break;
    
            case 2:
            {
            if(item > 5|| item < 1)
            printf("Error! Enter number from 1-5!\n");
            while(item > 5 || item < 1)
            {printf("Enter number of items to remove:");
            scanf("%d", &item);}
            }
    
            break;
            case 3:
            {
            if(item > 7 || item < 1)
            printf("Error! Enter number from 1-7!\n");
            while(item > 7 || item < 1)
            {printf("Enter number of items to remove: ");
            scanf("%d", &item);}
            }
            break;
            };
            for(j=1;j<=item;j++)
            {
            printf("Enter column(%d) number: ",j);
            scanf("%d",&column);
            };
            sum= i+i+i+i+i+i+i+i+i+i+i+i+i+i+i;
    
            }
    
            return 0;
            }

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It looks like you haven't written that part yet. Perhaps you should have a go at it first?

    Also:
    Code:
    sum= i+i+i+i+i+i+i+i+i+i+i+i+i+i+i;
    is the same as:
    Code:
    sum = i * 15;
    You made me go and count all those i's - grr!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Here is a formatted version of your code - It should always be indented like this
    Code:
    #include <stdio.h>
    main()
    {
        int row1[3]={1,1,1};
        int row2[5]={1,1,1,1,1};
        int row3[7]={1,1,1,1,1,1,1};
        int j; int i=1;
        int item; int l;
        int row; int player=1;
        int column; int sum;
    
    
    
    
    
    
        while (i<sum)
        {
            printf("\nPlayer %d's turn! \n\n",player);
            player++;
    
    
            if(player == 3)
                player = player - 2;
    
    
    
    
            printf("\tRow 1: %d %d %d\n",row1[0],row1[1],row1[2]);
            printf("\tRow 2: %d %d %d %d %d\n", row2[0],row2[1],row2[2],row2[3],row2[4]);
            printf("\tRow 3: %d %d %d %d %d %d %d\n",row3[0],row3[1],row3[2],row3[3],row3[4],row3[5],row3[6]);
    
    
            printf("\nEnter row number: ");
            scanf("%d", &row);
    
    
            if(row > 3 || row < 1)
            {
                printf("Error! Enter number from 1-3!\n");
    
    
                while (row > 3|| row < 1)
                {
                    printf("Enter row number: ");
                    scanf("%d", &row);
                }
            }
    
    
            printf("Enter number of items to remove: ");
            scanf("%d", &item);
    
    
            switch(row)
            {
                case 1:
                {
                    if(item>3||item<1)
                        printf("Error! Enter number from 1-3!\n");
    
    
                    while(item>3||item<1)
                    {
                        printf("Enter number of items to remove:");
                        scanf("%d", &item);
                    }
                }
                
                break;
    
    
                case 2:
                {
                    if(item > 5|| item < 1)
                        printf("Error! Enter number from 1-5!\n");
    
    
                    while(item > 5 || item < 1)
                    {
                        printf("Enter number of items to remove:");
                        scanf("%d", &item);
                    }
                }
    
    
                break;
    
    
                case 3:
                {
                    if(item > 7 || item < 1)
                        printf("Error! Enter number from 1-7!\n");
    
    
                    while(item > 7 || item < 1)
                    {
                        printf("Enter number of items to remove: ");
                        scanf("%d", &item);
                    }
                }
    
    
                break;
            };
    
    
            for(j=1;j<=item;j++)
            {
                printf("Enter column(%d) number: ",j);
                scanf("%d",&column);
            };
    
    
            sum= i+i+i+i+i+i+i+i+i+i+i+i+i+i+i;
    
    
        }
    
    
        return 0;
    }
    Optionally:

    *You do not need to put a ';' after any of those closing braces

    *You do not need to use braces under any of the case statements
    Fact - Beethoven wrote his first symphony in C

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by iMalc View Post
    It looks like you haven't written that part yet. Perhaps you should have a go at it first?

    Also:
    Code:
    sum= i+i+i+i+i+i+i+i+i+i+i+i+i+i+i;
    is the same as:
    Code:
    sum = i * 15;
    You made me go and count all those i's - grr!
    Mmm Sir how can we start it? we dont have idea of the conditions.
    if we will take 3 in row 1 it doesn't subtract.. we are stuck with this idea..
    so can help us?..

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    P.S can anyone help us so that our project will run like a charm just a simple help please cause we are stuck with this code.
    we dont know how to start the coding of the winner the game will just play but it cant determine the winner.. PLEASE HELP.

  6. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I'm not too sure what you want the program to do

    Can you please show us what you want the input/output to be?

    i.e.
    Player 1 turn!


    Row 1: 1 1 1
    Row 2: 2 2 2 2 2
    Row 3: 3 3 3 3 3 3 3


    Enter row number: 5
    Error! Enter number from 1-3
    Enter row number: 0
    Enter row number: 2


    ect...

    We'll need to see a full game with how to win or loose
    Fact - Beethoven wrote his first symphony in C

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by Click_here View Post
    I'm not too sure what you want the program to do

    Can you please show us what you want the input/output to be?

    i.e.
    Player 1 turn!


    Row 1: 1 1 1
    Row 2: 2 2 2 2 2
    Row 3: 3 3 3 3 3 3 3


    Enter row number: 5
    Error! Enter number from 1-3
    Enter row number: 0
    Enter row number: 2


    ect...

    We'll need to see a full game with how to win or loose
    Ok, The game will do like this..

    ROW1: I I I
    ROW2: I I I I I
    ROW3: I I I I I I I

    player can take any number in each row

    so player 1:

    Enter row number: 1
    Enter how many stick: 3

    ROW1:
    ROW2: I I I I I
    ROW3: I I I I I I I

    so player 2:

    Enter row number: 2
    Enter how many stick to remove: 5

    ROW1:
    ROW2:
    ROW3: I I I I I I I

    player 2

    Enter row number: 3
    How many stick: 6

    ROW1:
    ROW2:
    ROW3: I

    Player 1

    row number: 3
    How many stick: 1

    PLAYER TWO IS THE WINNER!

    INTRUCTION: you can get as many stick you want in a row.
    but the one who get the last stick will be the losser.
    Last edited by ervinako; 10-02-2012 at 07:29 PM.

  8. #8
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    This is my code.. can anyone add so that
    it will declare a winner?..

    Code:
    #include <stdio.h>
    main()
    {
        int row1[3]={1,1,1};
        int row2[5]={1,1,1,1,1};
        int row3[7]={1,1,1,1,1,1,1};
        int j; int i=1;
        int item; int l;
        int row; int player=1;
        int column; int sum;
    
    
    
    
    
    
        while (i<sum)
        {
            printf("\nPlayer %d's turn! \n\n",player);
            player++;
    
    
            if(player == 3)
                player = player - 2;
    
    
    
    
            printf("\tRow 1: %d %d %d\n",row1[0],row1[1],row1[2]);
            printf("\tRow 2: %d %d %d %d %d\n", row2[0],row2[1],row2[2],row2[3],row2[4]);
            printf("\tRow 3: %d %d %d %d %d %d %d\n",row3[0],row3[1],row3[2],row3[3],row3[4],row3[5],row3[6]);
    
    
            printf("\nEnter row number: ");
            scanf("%d", &row);
    
    
            if(row > 3 || row < 1)
            {
                printf("Error! Enter number from 1-3!\n");
    
    
                while (row > 3|| row < 1)
                {
                    printf("Enter row number: ");
                    scanf("%d", &row);
                }
            }
    
    
            printf("Enter number of items to remove: ");
            scanf("%d", &item);
    
    
            switch(row)
            {
                case 1:
                {
                    if(item>3||item<1)
                        printf("Error! Enter number from 1-3!\n");
    
    
                    while(item>3||item<1)
                    {
                        printf("Enter number of items to remove:");
                        scanf("%d", &item);
                    }
                }
    
                break;
    
    
                case 2:
                {
                    if(item > 5|| item < 1)
                        printf("Error! Enter number from 1-5!\n");
    
    
                    while(item > 5 || item < 1)
                    {
                        printf("Enter number of items to remove:");
                        scanf("%d", &item);
                    }
                }
    
    
                break;
    
    
                case 3:
                {
                    if(item > 7 || item < 1)
                        printf("Error! Enter number from 1-7!\n");
    
    
                    while(item > 7 || item < 1)
                    {
                        printf("Enter number of items to remove: ");
                        scanf("%d", &item);
                    }
                }
    
    
                break;
            };
    
    
            sum= i* 15;
    
    
        }
    
    
        return 0;
    }

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    That sounds like a fun little homework assignment Note that we can help you with your own code, but not give you any

    OK - The first think that I'd be doing is not working with the board, but just remembering how many sticks are in each row. For displaying the sticks, I would have a separate subroutine called "print_sticks(int r1, int r2, int r3)" which you entered the number of sticks in each row (r1/r2/r3) and the subroutine would loop through printing " I" for each sticks in the row.

    The advantages of doing it this way is that you can check to see if the subtraction is legal or not
    Fact - Beethoven wrote his first symphony in C

  10. #10
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by Click_here View Post
    That sounds like a fun little homework assignment Note that we can help you with your own code, but not give you any

    OK - The first think that I'd be doing is not working with the board, but just remembering how many sticks are in each row. For displaying the sticks, I would have a separate subroutine called "print_sticks(int r1, int r2, int r3)" which you entered the number of sticks in each row (r1/r2/r3) and the subroutine would loop through printing " I" for each sticks in the row.

    The advantages of doing it this way is that you can check to see if the subtraction is legal or not

    Wait wait.. let me try doing it..

  11. #11
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    instead of arrays i will use loop for printing this

    ROW1: I I I
    ROW2: I I I I I
    ROW3: I I I I I I I

    is this what you trying to say?..

  12. #12
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Your program does nothing. It asks for some numbers (within a range) but does nothing with them.

    sum = i * 15 ?
    Really?

    Presumably you want sum to be row1[0]+row1[1]+row1[2]+row2[0]+....
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  13. #13
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by oogabooga View Post
    Your program does nothing. It asks for some numbers (within a range) but does nothing with them.

    sum = i * 15 ?
    Really?

    Presumably you want sum to be row1[0]+row1[1]+row1[2]+row2[0]+....
    That why i'm asking how can i solve that problem.. cause i'm just in coding..

  14. #14
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Sort of - I'm suggesting that you have three variables that hold the amount of sticks in each row (int row1, row2, row3) instead of the arrays. To print the ROW1:... use a 'for' loop.

    Do you know how to write a subroutine and a 'for' loop?
    Fact - Beethoven wrote his first symphony in C

  15. #15
    Registered User
    Join Date
    Oct 2012
    Posts
    59
    Quote Originally Posted by Click_here View Post
    Sort of - I'm suggesting that you have three variables that hold the amount of sticks in each row (int row1, row2, row3) instead of the arrays. To print the ROW1:... use a 'for' loop.

    Do you know how to write a subroutine and a 'for' loop?
    Code:
     
    #include<stdio.h>
    
    int main ()
    {
        int row1, x;
    
        printf("Row1 :");
    
        for(row1 = 2; row1 > 0; --row1)
            {
                for(x = 0; x < row1; ++x)
                printf("\tI");
            }
    
        return 0;
    }
    I got it is this what you trying to say?..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 01:48 AM
  2. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  3. Project Help please!
    By black_hole??? in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2009, 12:55 AM
  4. C project
    By 666cos in forum C Programming
    Replies: 2
    Last Post: 03-11-2003, 09:32 AM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM