fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. return 0;
  6. }
  7.  
Success #stdin #stdout 0s 5292KB
stdin
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "foc fa22.h"

void startGuessTheNumberGame();
void startHangManGame();
int main ()
{

    int Choice;
    char user_Name[20];
    int user_Input=0;

    printf ("Enter you name: ");
    scanf("%s", user_Name);
    printf("Welcome %s!\n", user_Name);
    print ("Please enter the number of the game you wish to play, or choose Exit. \n");

    int looper=1;
    while(looper)
    {
        printf("1.Guess The Number. \n2.HangMan. \n3.Exit.\n");
        scanf("%d", &Choice);

        if(Choice==1)
        {
            printf("Guess the Number game has started! \n");
            printf("Enter a secret number between 1 and 10000:\n");

            scanf("%d", &user_Input);

            if (user_Input>=1 && user_Input<=10000)
            {
                startGuessTheNumberGame();
            }

            else
                printf ("Invalid choice");
            break;
        }


        else if(Choice==2)
        {
            startHangManGame();
        }
        else if(Choice==3)
        {
            printf("Exiting the game program.......\n") ;
            break;
        }
        else
        {
            printf("Invalid choice!\n Please choose one of the listed options\n");
        }
    }

    return 0;
}

void startGuessTheNumberGame()
{
    int maximum_Limit=10000,minimum_Limit=1,count=1,user_Choice=0;

    while (user_Choice!=1)
    {
        int middle_Of_Range=(maximum_Limit+minimum_Limit)/2;

        printf("The number I guessed is : %d\n", middle_Of_Range);

        printf ("Please choose one of the following 3 options: \n1.My guess is correct\n2. The secret number ts larger than %d\n3. The secret number is smaller than %d\n",middle_Of_Range, middle_Of_Range);
        scanf("%d", &user_Choice);
        switch (user_Choice)
        {
        case 1:
            printf("The secret number is: %d\n Amount of times taken to correctly guess the number: %d times\n", middle_Of_Range, count);
            break;
        case 2:
            minimum_Limit = middle_Of_Range + 1;
            count++;
            continue;
        case 3:
            maximum_Limit = middle_Of_Range - 1;
            count++;
            continue;
        default:
            printf("Please choose a valid option from the menu\n\n");
        }
    }


    int user_Choice2=0;
    int image_Array[150][150];

    while (user_Choice2 !=1)
    {
        for (int i=0; i<150; i++)
        {
            for (int k=0; k<150; k++)
            {
                image_Array[i][k]=255;
                if (i>150-(count*10) && (k>65 && k<85))
                    image_Array[i][k]=0;
            }
        }
        showArray(150,150,image_Array);
        break;
    }
}




void startHangManGame()
{
    FILE*Hangman;
    char word[50]=" ";
    char word2[50]=" ";
    char user_Guess;
    int hangman_Game_Choice;
    int random,count=0,exit=0,looper2=1;

    while (looper2)
    {
        printf("choose one of the categories: \n1. Food\n2. Colors\n3. Names\n4. Objects\n");
        scanf("%d", &hangman_Game_Choice);
        switch (hangman_Game_Choice)
        {
        case 1:
            Hangman=fopen("Food.txt", "r");
            looper2=0;
            break;
        case 2:
            Hangman=fopen("Colors.txt", "r");
            looper2=0;
            break;
        case 3:
            Hangman=fopen("Names.txt", "r");
            looper2=0;
            break;
        case 4:
            Hangman=fopen("Objects.txt", "r");
            looper2=0;
            break;

        default:
            printf("invalid Choice\n");

            break;
        }

        srand(time(NULL));
        random = rand () % 15;
        for(int i=0; i<random ; i++)
        {
            fscanf(Hangman, "%s", word);
        }
        fclose(Hangman);

        int length=strlen(word);
        count=length+1;

        for(int l=0; l<length; l++)
        {
            word2[l]='-';
        }

        for (int k=0; k<length+1; k++)
        {
            printf("The word so far is\n");
            for (int z=0; z<length: z++)
            {
                printf("%c", word2[z]);
            }
            printf("\nYou have %d attempts remaining:", count);
            scanf("%c", &user_Guess);

            for (int i=0; i<length; i++)
            {
                if (user_Guess==word[i])
                {
                    printf("\nYou have %d attempts remaining: ", count);
                    scanf("%c", &user_Guess);

                    for (int v=0; v<length; v++)
                    {
                        if (user_Guess==word[v])
                        {
                            word2[v]=user_Guess;
                            printf("Correct! Keep going\n");
                            exit=1;
                        }
                    }
                    if (exit==0)
                    {
                        printf("Not quit! Try again!\n");
                    }
                    if(strcmp(word,word2)==0)
                    {
                        break;
                    }
                    count --;
                }

                if (strcmp(word,word2)==0)
                {
                    printf("Congratulations!! You found the word!\n");
                }
                else
                {
                    printf("Hard luck! You were not able to find the word :( \n");
                }
            }
        }
    }
}
stdout
Standard output is empty