While loop error | Sololearn: Learn to code for FREE!

0

While loop error

I don't understand why program doesn't work. It should print 3,6,9,12,15,18; #include <iostream> using namespace std; int main() { //change the code int num = 0; while(num<=20){ if (num%3=0) cout <<num; else num+=1; return 0; }

7/31/2021 1:13:01 PM

vilrau12

11 Answers

New Answer

+5

ok?vilrau12 https://code.sololearn.com/c6JtylxjVJOK/?ref=app

+5

There are a few things, you can see in the update as follows: #include <iostream> using namespace std; int main() { //change the code int num = 0; while(num<=20){ if (num%3==0) cout <<num<<" "; // else num+=1; } return 0; }

+3

Not all can see the pro tasks.

+2

In the name of kindly generous ALLAH Thanks ALLAH hello vilrau12 add a closed curly brack '}'on after num+=1; so ..... num+=1;} return 0;}

+2

Thanks I see what I did wrong, but the program still doesn't work properly..

+1

So i have this: #include <iostream> using namespace std; int main() { //change the code int num = 0; while(num<=20){ cout<<num<<endl; num+=1; } return 0; } and I need to change the program to only print 3,6,9,12,15,18 instead of all from 1 to 20

+1

https://code.sololearn.com/c6JtylxjVJOK/?ref=app

+1

vilrau12 ++num it is about num=num+1; or num+=1; and for --num num=num-1; num-=1; so ++increase or --decrease value one step once, and returned the changed value e: int num = 0; cout<<++num<<num<<endl; cout<<num; //11 //1

+1

#include <iostream> #include <string> using namespace std; int num=20; while (num >= 1){ num-=1; If((num%3)==0){ cout<<num; continue; } else{ continue; } } /*IMHO this should work*/

0

yes thank you, i didn't know this ++num thing thanks