For Loop help

Hello Everyone. I have to write a For Loop that prints multiples of 5 from 1 to 400. So far this is what I have, but I can't figure out how to jump from 1 to 5 and go 5, 10, 15, 20, and so on to 400. I know I have it to where it goes 1, 6, 11, 16, and so on because I'm adding 5 to it, but how do you jump from 1 to 5 and go from there?

#include <iostream>


using namespace std;

int main()
{
int num;

for(num = 1; num <= 400; num += 5)
{
cout << num;
cout << '\n';


}


system("pause");
return 0;
}
Seriously? Is one a multiple of 5?

Aceix.
it starts at 1 and goes 5, 10, 15, 20 and so forth to 400.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include <iostream>


using namespace std;

int main()
{
int num;
for(num = 0; num <= 400; num = num + 5)
{

    cout << num;
    cout << '\n';



}


system("pause");
return 0;
}



now u just gotta find a way to cout << "1 " b4 the loop... other than that, its not too difficult...
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
    int num = 1 ; // start with 1
    std::cout << num << '\n' ;

    // and then, starting with 5, and incremet of 5
    for( num = 5 ; num <= 400 ; num += 5 )     std::cout << num << '\n' ;
}
Well, yeah. You can just:

cout << "1\n";

before the For Loop, but I was just wondering if there was a way to start at 1 and jump to 5, 10, 15 with just using the For Loop.
@JLBorges

That worked. Thanks!
> if there was a way to start at 1 and jump to 5, 10, 15 with just using the For Loop.

There is. But...
Do you want to write your code in a somewhat obfuscated way?
1
2
for( int num = 1 ; num <= 400 ; num += 4 + (num>1) ) 
    std::cout << num << '\n' ;

Or would you rather keep it simple, clear and transparent as in the first example?
Topic archived. No new replies allowed.