# Help for our project

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 10-02-2012
ervinako
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;         }```
• 10-02-2012
iMalc
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!
• 10-02-2012
Click_here
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
• 10-02-2012
ervinako
Quote:

Originally Posted by iMalc
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?..
• 10-02-2012
ervinako
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.
• 10-02-2012
Click_here
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
• 10-02-2012
ervinako
Quote:

Originally Posted by Click_here
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.
• 10-02-2012
ervinako
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; }```
• 10-02-2012
Click_here
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
• 10-02-2012
ervinako
Quote:

Originally Posted by Click_here
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..
• 10-02-2012
ervinako
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?..
• 10-02-2012
oogabooga
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]+....
• 10-02-2012
ervinako
Quote:

Originally Posted by oogabooga
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..
• 10-02-2012
Click_here
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?
• 10-02-2012
ervinako
Quote:

Originally Posted by Click_here
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?..
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last