I cannot figure out why my do- while loop does not work when i enter negative nu
ID: 3753144 • Letter: I
Question
I cannot figure out why my do- while loop does not work when i enter negative number. it should ask 3 times before exiting the loop, unless an acceptable number is given. It works fine if i give 3 values over 5 digits, but does not function correctly when I use negative numbers. This is in C++.
using namespace std; E int main) 6 bool stepOne - 8; bool stepTwo e; 8 bool stepThree 8; 9 bool stepFour e int menuoption; 12 int caseOneInt, caseTwoInt; 13 int nun tries e; 14 int num tricsTwo -e; 15 int n-1; 16 int tenThousands, tenThousandsRenainder, thousands, thousandsRemainder, hundreds, hundredsRemainder, tens, tensRemainder, ones; 17 int baseTen; "Explanation / Answer
Solution:
change your while condition to
while((caseOneInt < 0 || caseTwoInt > 99999) && num_tries<3)
please let me know if this works fine, also always try to give the code in the text format on the Q&A so that it will be better for us experts to run and see so that we can provide you an executable code in short time.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.