Hi guys I'm having major issues with this assignment of mine and I cant even figure out where to get started. Any help would be greatly appriciated.

I must write a program that outputs that plays the game Hi Lo with a user until they decide to quit. The program should continue playing Hi Lo keeping an updated score until the user elects to quit.

The rules of Hi Lo (for the purposes of this assignment) are as follows:

The game is played with a standard deck of playing cards
The player is dealt one card face up so the value is visible.
The player must guess if the next card will be higher or lower than the visible card.
The second card is dealt. If the player is correct, a point is awarded. If the player is incorrect, a point is subtracted from the score.
If the second card is the same value as the first card, the score does not change.
Gameplay repeats for as many rounds as desired

There are several right ways to accomplish each of the requirements below.

My game must allow the user to play as many rounds of HiLo as desired without restarting the program. (use a loop)
Each round should follow the rules listed earlier in the assignment description.
The score must accumulate for the entire play session (until the user quits)
When the user quits, print out the final score
Use rand to pick a card.
The numbered cards 2-10 will be represented as the numbers 2-10 and jack, queen, king and ace will be represented as 11 through 14 respectively.
I will need to ask the user to enter one three menu options for each card: high (1), low (2), or quit(0)
Use 1, 2, 0 as the input for the menu choices (as shown above)
Check the users input to make sure it is only one of the allowed options. Program defensively
I will need to keep track of the users score and print it out every round, including at the end when the user quits.

this is all I have so far (sad I know)

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

int main(void)
{
    int randomNumber;
    int sizeOfDeck;
    int guess;


    sizeOfDeck = 13;

    srand (time(NULL));
    randomNumber = rand()%sizeOfDeck+2;
    printf("The Current Card Is a: %d\n", randomNumber);

    printf("Will the next card be higher(1) or lower(2)? (press 0 to quit)\n");
    scanf("%d", &guess);

    return 0;
}

Break down the requirements into manageable chunks. I'd do it like this:

  1. Play a single round of HiLo with numbers from 1 to 100.
  2. Modify the program to play infinite rounds.
  3. Modify the program to keep score or wins and losses.
  4. Modify the program to let the user stop after each round.
  5. Modify the program to use "cards" instead of a simple number range. Reshuffle the deck on each round.
  6. Modify the program to use a full deck before reshuffling.
  7. Profit!

This incremental approach keeps things simple as you only have to worry about a subset of the requirements at any given time. Further, when adding new requirements, you already have a fully working program to build upon.

I don't quite know how to code it from there, I don't know how to do the loops, so that it keeps going till the user decides to stop. Is there an example code you could show me?

Here's an example that may help. Note that it's not a complete solution to your problem, just a similar example:

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

int draw_card()
{
    return 1 + rand() % 100; // [1,100]
}

int main(void)
{
    int wins = 0, losses = 0;

    srand((unsigned)time(NULL));

    // Game loop: plays infinite rounds of HiLo
    while (1) {
        int card = draw_card();
        int guess;

        fputs("High(1) or Low(2)? ", stdout);
        fflush(stdout);

        // Get a sanitized guess
        while (scanf(" %d", &guess) != 1 || (guess != 1 && guess != 2)) {
            puts("Invalid option");
        }

        // Clear extraneous characters from the stream
        while (getchar() != '\n');

        // Check the guess, notify, and update stats
        if (guess == 1) {
            if (card >= draw_card()) {
                puts("You win!");
                ++wins;
            }
            else {
                puts("You lose");
                ++losses;
            }
        }
        else {
            if (card < draw_card()) {
                puts("You win!");
                ++wins;
            }
            else {
                puts("You lose");
                ++losses;
            }
        }

        // Give the user the option to quit
        fputs("Play another round? (y/n): ", stdout);
        fflush(stdout);

        if (tolower(getchar()) != 'y') {
            break;
        }
    }

    printf("Final Score: wins(%d) losses(%d)\n", wins, losses);

    return 0;
}
commented: you are awesome! +0

thank you so much! Now I have an idea of how to go about things.

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.