0

This is part of a program I'm trying to do but the printf("Do you want to exit? [Y/N] "); repeats itself and I don't know why.

This is the code

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

int main(void)
{
    int repeat = 1;
    while(repeat == 1)
    {
        
        printf("0: Exit\n\n");

        int func = -1;
        printf("Choose an option: ");
    
        while (1)
        {
            scanf("%d", &func);

            if (func == 0)
            {
                char confirm;
                printf("Do you want to exit? [Y/N] ");
                scanf("%c", &confirm);
                if (confirm == 'y' || confirm == 'Y')
                {
                    repeat = -1;
                    break;
                }
                else if (confirm == 'n' || confirm == 'N')
                {
                    break;
                }
            }

            if (repeat == -1)
                break;


        }
    }       
    printf("Program finished\n");
    return 1;
}   

void clearScreen()
{
    system("clear || cls");
}

The printf("Do you want to exit? [Y/N] "); should be seen only one time but it gets repeated before the printf("Program finished\n");

Can anyone help me?

9Meteor6
  • 1
  • 2

0 Answers0