How to deduct 100 to zero using nested for loop c++ -
basically program deduct 100 2 person until reach zero. i'm using nested loop. 1 loop each person person need enter integer. integer deducted 100.
but main problem can't repeat 1st loop without losing current value of 100. i'm beginner.
for( int x = 1; x<=100;) { cout <<"\n\n"<< np1 <<" how many of remaining " << chips<<" chip(s) like?"<<endl; cin >> p1c; result = chips-p1c; cout <<result; for( int y = 1; y <=100;) { cout <<"\n\n"<< np2 <<" how many of remaining " << result<<" chip(s) like?"<<endl; cin >> p2c; result = result-p2c; cout <<result; break; }
for-loops aren't suited – "repeat until zero", you're describing problem, different "repeat 1 hundred times", tried solve it.
if playing in real life, this:
while there chips left let person 1 pick chips if there still chips left let person 2 pick chips
translating code left exercise.
Comments
Post a Comment