mercredi 28 avril 2021

Counting multiple used if statments in one loop

Currently learning C and I could use a bit of a nudge in the right direction. I'd like to know what options I have for stage I'm at. Not know much of anything you all will know what terms to search for.

I need to provide a print out of the number of correct / incorrect guesses and times the game was played.

In essence tally how many times each of the 3 if statements have been used within a while loop.

I'm thinking I'd like to have 3 variables for each if statement that can be a used as a tally and added up each time it's accessed. I'd think I'd like to use an array as I've not yet practiced with that and would be a neat way to tally and recall values.

It's for an assignment so I've only provided a general skeleton of the code to avoid any issues with that.

Any thoughts on how to approach this would be appreciated.

          /* While loop to continue game */
        while (code) {
            
            /* Code to prompt for and read the user’s guess. */
            printf("txt")
            scanf();
            

            /* If guess is correct. */
            if (test code) {
                printf("txt");
                *code to count correct guess here*

            }
            /* If guess is incorrect but an odd number. */
            if (test code) {
                printf("txt");
                *code to count incorrect guess here*
            }
            /* If guess is incorrect but an even number. */
            if (test code) {
                printf("txt");
                *code to count incorrect even guess here, maybe do a double tally with above?*
            }
            /* Ask to play again. */
                printf("txt"); 
                scanf();
                *code to count games played here*
    
                if (code) {
                    printf("txt")
                    exit(EXIT_SUCCESS);

Aucun commentaire:

Enregistrer un commentaire