What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help C programming

Hotsause03

Honorary Poster
Established
Joined
Jan 12, 2016
Messages
688
Reaction score
1,346
Code:
            char decision;
            printf("\n\n\t\t\t Are you sure (Y/N)?");
            scanf("%s",&decision);
            if(decision=='y'||decision=='Y'){
                printf("\n\n\t\t\tThanks for buying please come back next time");
                sleep(2);
                printf("\n\n\t\t\tClosing in 3 Seconds ...");
                sleep(3);
                exit(0);
            }
            else if(decision=='n'||decision=='N'){
                mainmenu();
            }
            else {
                printf("\n\n\t\t\tReturning to Main Menu");
                sleep(2);
                mainmenu();
            }
possible ba na kahit hindi ko na tanungin yung user na mag input ng letter ?
ang magyayare kapag pinindot ko yung 'N' automatic na sya mapupunta sa main menu ? tapos kapag 'Y' naman ma eexit sya ayun sa code.
Yung hindi ko na kailangan mag lagay ng " Enter your choice: " sa baba ? rekta na agad pagka pindot ? pwede kaya yun ?
 

Arcturus

Forum Guru
sa mga ganyang situation paps, gawa ka ng method/function para ma i check kung n or y lang ang ininput nya
 

Arcturus

Forum Guru
parang ganito lang sya paps,
C++:
bool decisionVerifier(string decision){
    if(decision.length() > 1)
        return false;
    char isValid = decision[0];
    return isValid == 'y' || isValid == 'Y' || isValid == 'n' || isValid == 'N';
}
 

mrHazan

Eternal Poster
Parang ang gusto ata niya kapag pinindot ang n or y key without pressing enter key, mapaprocess na agad yung input.
Kasi basic naman kung gusto lang niya walang "Enter your choice: ", di tanggalin, ni wala ngang "Enter your choice: "sa code.
 
Top