Jump to content
OneHallyu Will Be Closing End Of 2023 ×
OneHallyu

HELP! anyone who knows how to code?


dux

Recommended Posts

char cont;do {     while(cont != 'y' || cont != 'n'){        printf("Do you want to continue? (y/n)");        fflush(stdin);        scanf("%c", &cont);        };}while(cont == 'y');

i want the person to input charcater either 'y' or 'n'. if they enter 'n' the program should end, but it wont? why? it just keeps looping?

Link to comment
Share on other sites

The condition on your while loop causes it to loop forever. Also there shouldn't be a semicolon after your while loop

im trying to make it so 'y' will make it keep going, but 'n' should end the program...whats wrong

Link to comment
Share on other sites

im trying to make it so 'y' will make it keep going, but 'n' should end the program...whats wrong

Maybe change || to &&? Don't take my word for it though.. 

 

The way I see it, in the case of ||, if you enter N, the cont != 'y' will be True and make the whole condition True thus making the while loop go on. I coded very long time ago, I may be wrong.

Link to comment
Share on other sites

im trying to make it so 'y' will make it keep going, but 'n' should end the program...whats wrong

char cont;
do {
     while(cont != 'y' && cont != 'n'){
        printf("Do you want to continue? (y/n)");
        fflush(stdin);
        scanf("%c", &cont);
        }
}while(cont == 'y');
Link to comment
Share on other sites

 

char cont;
do {
     while(cont != 'y' && cont != 'n'){
        printf("Do you want to continue? (y/n)");
        fflush(stdin);
        scanf("%c", &cont);
        }
}while(cont == 'y');

 

 

 

Maybe change || to &&? Don't take my word for it though.. 

 

The way I see it, in the case of ||, if you enter N, the cont != 'y' will be True and make the whole condition True thus making the while loop go on. I coded very long time ago, I may be wrong.

thank you guys sooo much

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Back to Top