Do while loop goes infinity | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Do while loop goes infinity

When I use this statement While (res=='N' || res=='n') it goes infinity But when I use this one While (res=='N' && res=='n') It suppose continue looping when variable res is either 'N' or 'n' not 'N' and 'n' Any help with that ? https://code.sololearn.com/c81avN8LDROY/?ref=app

21st Aug 2023, 8:42 PM
الحسين محمد عبدالله
الحسين محمد عبدالله - avatar
6 Answers
+ 1
Can you tell the entire params string that you use for executing?
21st Aug 2023, 9:16 PM
KrOW
KrOW - avatar
0
KrOW Char respond; std::cout<<"Do another one? (y/n) : "; std::cin>>respond; }while(respond!='n' && respond!='N');
22nd Aug 2023, 5:13 PM
الحسين محمد عبدالله
الحسين محمد عبدالله - avatar
0
I mean the arguments that you pass to program.. Trying 1 1 n n i cannot see problems
22nd Aug 2023, 5:50 PM
KrOW
KrOW - avatar
0
KrOW my code is not well organized, I'm sorry for that. My code works fine when the while condition is (respond=='N' && respond =='n') But when the condition becomes (respond=='N' || respond =='n') The code loops infinitely Why is that happening? Isn't or (||)more logical than and(&&)?
24th Aug 2023, 8:05 PM
الحسين محمد عبدالله
الحسين محمد عبدالله - avatar
0
Are you referring to line 129? I dont understand to which line you referring...
24th Aug 2023, 8:27 PM
KrOW
KrOW - avatar
0
KrOW Yes
24th Aug 2023, 10:22 PM
الحسين محمد عبدالله
الحسين محمد عبدالله - avatar