dux 3,142 Posted October 23, 2017 Share Posted October 23, 2017 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 More sharing options...
Almondandlime 6,854 Posted October 23, 2017 Share Posted October 23, 2017 The condition on your while loop causes it to loop forever. Also there shouldn't be a semicolon after your while loop Link to comment Share on other sites More sharing options...
dux 3,142 Posted October 23, 2017 Author Share Posted October 23, 2017 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 More sharing options...
Jiraishin 1,276 Posted October 23, 2017 Share Posted October 23, 2017 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 More sharing options...
Almondandlime 6,854 Posted October 23, 2017 Share Posted October 23, 2017 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 More sharing options...
kyulkyung 5,023 Posted October 23, 2017 Share Posted October 23, 2017 you guys are smart i have no idea what's going on Link to comment Share on other sites More sharing options...
BoopBoop2 519 Posted October 23, 2017 Share Posted October 23, 2017 NERDS!!!!! Link to comment Share on other sites More sharing options...
dux 3,142 Posted October 23, 2017 Author Share Posted October 23, 2017 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.