#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<stdbool.h>

int roll(void)
{
	int num = (rand()%6)+1;
	return num;
}

/*
void player(void)
{
	int i=0;
	int sum=0;
	int dice;
	char turn;
	while(i!=6)
	{
		printf("Player 1- roll or hold?\n");
		turn = getchar();
		while(getchar()!='\n');
		if(turn=='r')
		{
	   		dice = roll();
	    	if(dice!=1)
	    	{
	         	sum+=dice;
	         	printf("Rolled =  %i Your turn total = %i\n",dice,sum);
	    	}
	   		else
	    	{
				sum=0;
	    	}
		}
		else if(turn =='h')
		{
	    	printf("Your total score is = %i\n",sum);
		}
	 	i++;
	}
}

*/
int sum1player2=0;
void player2(void)
{
	_Bool j=true;
	int sum1=0;

	int dice;
	char turn;
	while(j)
	{
	    printf("Player 2- roll or hold?\n");
	    turn = getchar();
	    //j++;
		while(getchar()!='\n');
	    if(turn=='r')
	    {
	        dice = roll();
	        if(dice!=1)
	        {
	            sum1+=dice;
	            printf("Rolled =  %i Your turn total = %i\n",dice,sum1);
	        }
	        else
	        {
	            printf("Sorry, you rolled 1, Your score is 0 \nNext player turn.");
	            j=false;
	        }
	    }
	    else if(turn =='h')
	    {
	        j=false;
	        sum1player2+=sum1;
	        printf("Your total score is = %i\n",sum1player2);
	    }
	}
	if(sum1player2 < 100)
	{
        player1();
	}
	else
	{
        printf("player 1 wins");
    }

}

int sumPlayer1=0;
int player1(void)
{
   _Bool k=true;
   int sum=0;
   int dice;
   char turn;
   while(k)
   {
     printf("Player 1 - roll or hold?\n");
     turn = getchar();
     while(getchar()!='\n');
     if(turn=='r')
     {
         dice = roll();
         if(dice!=1)
         {
             sum+=dice;
             printf("Rolled = %i Your turn total = %i\n",dice,sum);
         }
         else
         {
            printf("Sorry, you rolled 1, Your score is 0 \nNext player turn.");
            k=false;
         }
     }
     else if(turn =='h')
     {
          k=false;
          sumPlayer1+=sum;
          printf("Your total score is = %i\n",sumPlayer1);;
     }
    }
    if(sumPlayer1 < 100)
    {
        player2();
    }
    else
    {
        printf("player 2 wins");
    }
	return 0;

}


int main(void)
{
	srand(time(NULL));
	player1();
}

The error part, when I run this program. I get a warning saying prototype for player1 missing, I know there is something wrong with the functions. Any help please.

Recommended Answers

All 3 Replies

Put this line before the function player2

int player1(void);

Thanks a lot gerard4143

Hei, that solved the problem but can you explain what you did, and I was ruining my code using tons of pointers here and there.

Its called forward declaration and its used so the compiler has an idea what player1 is.

int player1(void);

This is all the information the compiler needs to generate a function call to player1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.