Как сделать так, чтобы в конце игры пользователь мог решить, сыграть сначала или выйти из программы?

#include <stdio.h> 
#include <stdlib.h>
#include <time.h>
int a, b;                                                                          
int i = 20, flag = 1; 
int c = rand()%100 + 1;                                                           
int x = 0;                                                                              
int low = 1;                                                                          
int high = 100; 
int y = 0;

int main(void)
{ srand(time(NULL)); 
       
                                                                                  

    printf("Make a choise, who guesses the number: Computer-1 or You-2\n");             
    scanf ("%d",&a);
        if (a>2)                                                                       
    printf("1 or 2 numbers only\n");                  
    switch(a){                                                                          
    
        case 1:                                                                       
        printf("The computer has thought of a number from 1 to 100.\nTry to guess what number it is.\n"); 
        printf("Write down your number and remember you got 20 attempts.\n");
        
            for (i=1; i<=20; i++){
            printf("%d-try. \nNumber:",i);  
            scanf("%d",&b);
            
            if (b > c)
            printf("Try another smaller one\n"); 
            
            else if (b < c)
            printf("Try another bigger one\n");
            
            else{
                flag=1;
                break;
                }
            }
            if (flag)
            printf("Conngratulations, you win!\nNumber of attempts: %d\n",i);
            
            else
            printf("We are sorry, but you lose\n");
            return 0;
            
            
        case 2 :
        printf("Enter a number from 1 to 100\n"); 
        scanf("%d", &x); 

            if(x > 100)
            printf("More than 100 is not available\n");

            if(x < 1)
            printf("Less than 1 is not available\n");
 
            while (y != x){ 
            y = ((high - low)/2 + low); 
            printf("%d", y); 
            
            if (x > y) { 
            printf("Computer guess was low\n"); 
            low = y+1; 
            } 
            else if (x < y) { 
            printf("Computer guess was high\n"); 
            high = y-1;
            } 
            else if (x == y){
            printf("The computer figured out the number you previously thought\n"); 
            } 
        } 
    return 0;}}

Ответы (1 шт):

Автор решения: F48D1

Обернуть весь код в цикл while, и в конце тела цикла спрашивать ответ пользователя, после проверять его в проверки цикла.

→ Ссылка