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

  • SEARCH
  • Home
  • 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 8748459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:31:45+00:00 2026-06-13T12:31:45+00:00

#include <stdio.h> #include <time.h> int main(void) { int games = 0; int stayWins =

  • 0
#include <stdio.h>
#include <time.h>
int main(void)
{
    int games = 0;
    int stayWins = 0;
    int switchWins = 0;
    int chosenDoor;
    int remainingDoor;
    int revealedDoor;
    int winningDoor;
    int option;

    srand (time(NULL));

    do
    {
    chosenDoor = rand() % 3 + 1;
    winningDoor = rand() % 3 + 1;
        do
        {
            revealedDoor = rand() % 3 + 1;
        } while (revealedDoor == chosenDoor || revealedDoor == winningDoor);

        do
        {
            remainingDoor = rand() % 3+1;
        } while (remainingDoor == chosenDoor || remainingDoor == revealedDoor);

        option = rand() % 2 + 1;
        if (option == 1)
        {
            if (chosenDoor == winningDoor)
            {
                stayWins++;
            }
        }
        if (option == 2)
        {
            chosenDoor = remainingDoor;
            if (chosenDoor == winningDoor)
            {
                    switchWins++;
            }
        }
        games++;
    } while (games < 10000);

printf("Out of 10,000 games, the contestant won %d times by staying with his/her original choice and won %d times by switching his/her choice.",stayWins,switchWins);

    return 0;
}

Evening guys,
Here is a completed Monty Hall Problem code that prints the results of 10,000 games. The code will choose the chosen door for the user. How can I change it so the program will allow the user to choose himself?
As well, how can I modify it so the program won’t randomize values of ‘1’ or ‘2’ for the program but instead allows me to make the option of switching?
My progress…
Instead of this:

chosenDoor = rand() % 3 + 1;

Use this, where only acceptable input is 1, 2, or 3 :

printf("Choice:");
scanf("%d",&chosenDoor);

Is this the right track? I’m aware at this point the user will then need to input his choice 10,000 times before the program ‘finishes’, so is there a way I can apply the first choice to the other 9,999 trials?

  • 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-06-13T12:31:46+00:00Added an answer on June 13, 2026 at 12:31 pm

    Is there a way I can apply the first choice to the other 9,999 trials?

    Move the

    printf("Choice: ");
    scanf("%d", &chosenDoor);
    

    part of the code outside the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
Consider the following code which shows compile time error : #include <stdio.h> int main(int
#include <stdio.h> #include <stdlib.h> #include <time.h> void initDeck (int deck[]); void showDeck (int deck[]);
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
Can someone explain this behaviour? test.c: #include <stdio.h> int main(void) { printf(%d, %d\n, (int)
#include <stdio.h> int main(void) { int i,j; int wordstart = -1; int wordend =
#include <stdio.h> #include <math.h> int main (void) { float inches; printf(Enter the number of
I have the following program #include <stdio.h> int main(void) { unsigned short int length
Here is my program time_play.c : #include <stdlib.h> #include <stdio.h> #include <time.h> int main

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.