Question

Program prints a message telling the user to push a key to start the game. Once...

  • Program prints a message telling the user to push a key to start the game.

  • Once in game, output tells the player which key to push. The key to press should be determined randomly. Game runs until wrong key is pressed.

  • Include timer function with each round decreasing the time (2.5 seconds-2seconds-1.5seconds-etc until 0.

  • Once hit 0 you win.


c programming

Homework Answers

Answer #1

Please find the requested program below. Also including the screenshot of sample output and code to understand the indentation

Please provide your feedback
Thanks and Happy learning!

#include <stdio.h>
#include<stdlib.h>
#include <time.h>
#include <ctype.h>
int main()
{
    srand(time(NULL));

    char cUserInput;
    char randLetter = (rand() % 26) + 'A';

    //Program prints a message telling the user to push a key to start the game.
    printf("Press %c to start the game\n", randLetter);
    scanf_s(" %c", &cUserInput, sizeof(cUserInput));

    double duration = 2.5; //seconds
    time_t startTime;
    time_t currentTime;
    char cUserInputUpper = toupper(cUserInput);
    while ((cUserInputUpper == randLetter))
    {
        //Once in game, output tells the player which key to push.
        //The key to press should be determined randomly.
        //Game runs until wrong key is pressed.
        if (duration == 0)
        {
            printf("You WON!!\n");
            break;
        }

        randLetter = (rand() % 26) + 'A';
        printf("Press %c \n", randLetter);
        startTime = time(NULL);
        scanf_s(" %c", &cUserInput, sizeof(cUserInput));
        cUserInputUpper = toupper(cUserInput);
        currentTime = time(NULL);
        if (currentTime - startTime > duration)
        {
            printf("You LOOSE!. Timed out.\n");
            break;
        }
        duration = duration - 0.5;

    }

    getchar();
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT