Hi everyone! I`m new here in daniweb.
Our Prof. want us to make a game w/ a menu.
I already made the game but my main menu is the problem.
how to make a menu that after the game it will ask.
Do you want to try again >>> then will go back to menu?
thanks

Recommended Answers

Sure.one way to do it is, put the whole program in an infinite loop and ask the user each time whether to continue or not. Check the user's answer
if yes loop back
else end the loop and exit.

Jump to Post

All 2 Replies

Sure.one way to do it is, put the whole program in an infinite loop and ask the user each time whether to continue or not. Check the user's answer
if yes loop back
else end the loop and exit.

Here's one possible implementation of diwakar's algorithm:

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

int is_finished(void)
{
    char line[BUFSIZ];
    
    fputs("Again? (y/n): ", stdout);
    fflush(stdout);
        
    return fgets(line, sizeof line, stdin) == NULL
        || toupper(line[0]) != 'Y';
}

int main(void)
{
    do {
        puts("Doing stuff...");
    } while (!is_finished());
    
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.