division

how to use a for loop that prints out the numbers 5 to 100, counting by fives? i`m new too c++, i`ll appreciate ur help bcause i learn something from that.
Last edited on
for ( int i = 5; i <= 100; i += 5 ) std::cout << i << std::endl;
Last edited on
for ( int i = 5; i <= 100; i += 5 ) std::cout << i << std::endl;

Lets break it down, so it'll be easier to learn from. First, the

For( //this starts the for loop

int i=5; //this denotes that "i" is going to be the counter for the loop, and starts it at count 5

i<=100; //this is the continue condition, so while i is less than/equal to 100, the loop continues

i+=5) //every time the loop continues, add 5 to i

std::cout << i << std::endl; //this just prints the value of i on the screen and then ends the line, so that next time it prints it will print one line lower
Topic archived. No new replies allowed.