Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I have a for loop which is driving me crazy!!! Help!!! there is a loop #

ID: 441415 • Letter: H

Question

Hello, I have a for loop which is driving me crazy!!! Help!!! there is a loop # include using namespace std; int main(){ int s, t = 0; for(s=8; s>=4; s=s-3){ if(s>t) t+=3; if(s<=t) s+=2; cout<<"s= "<<s<<" "<<"t= "<<t<<endl; } return 0; } here is its answers which the program gives me: s=8 t=3 s=7 t=6 s=6 t=6 when I trace it by myself I got next values: s=8 t=3 s=5 t=6 s=2 What is wrong with my trace??? why the program does second if when s=8 and t=3? I cannot get it. Please help!!!

Explanation / Answer

Hahaha, dude... I get it where you are going wrong if(s>t) t+=3; if(st) t+=3; else s+=2; Now, this will give you the correct answer
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote