Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4343816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:48:28+00:00 2026-05-21T11:48:28+00:00

wiHi everyone since last time i found extreme help on here, im gonna ask

  • 0

wiHi everyone since last time i found extreme help on here, im gonna ask a question again

My code doesnt return right values :
something is wrong in the play_game function and i cant figure out what it is.I believe that all cases are covered but somehow they end up messed up.
also the code doesnt loop for everytime i want to play a game after the second game it stops.
this is not an assignment

any suggestion?

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

static int sum, point, win = 0, roll = 0;    
bool play_game(void);
int roll_dice(void);

int main(void){

srand(time(NULL)); 


play_game();

char input[10];

do{ point = 0;
    play_game();
    if(win == 1){ // I'm assuming that play returns whether you won or not
        printf("You won!\n");
    }else{
        printf("You lost!\n");
    }
    printf("Would you like to continue? y/n\n");
    gets(input);
}while(*input == 'y'); // gets() flushes the buffer for next time you need input
return 0;
}


bool play_game(void){

point=0;
roll_dice();
printf("Your point is %d\n", sum);

while(roll == 1) /* first round */
{
  if(sum == 7 || sum == 11)
     return win = 1;
  else if(sum == 2 || sum == 3 || sum == 12)
     return win = 0;
  else if(sum == 1 || sum == 4 || sum == 5 || sum == 6 || sum == 8 || sum == 9 || sum    == 10){
     point=sum;
     roll_dice();
     }

}

while(roll > 1) /* all others rounds*/
{  
      if(sum == 7)
        return win = 0;
      else if(sum == point)
        return win = 1;
      else if(sum != point || sum != 7)
      roll_dice();

} 

}

int roll_dice(void){

int a,b;

a=1+rand() % (6);
b=1+rand() % (6);
sum=a+b;
roll++;
printf("You rolled %d\n", sum);
return sum;

}

OUTPUT

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:48:29+00:00Added an answer on May 21, 2026 at 11:48 am

    The loop needs to be more like:

    main(){
        char input[10];
    
        do{
            score = 0; //Always initialize the score
            if(play_game()){ // I'm assuming that play returns whether you won or not
                printf("You won!\n");
            }else{
                printf("You lost!\n");
            }
            printf("Would you like to continue? y/n\n");
            gets_s(input, 9);
        }while(*input == 'y'); // gets() flushes the buffer for next time you need input
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.