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; }
11 Antworten
+ 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
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
#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



