loop

Dec 14, 2009 at 3:03am
This is my loop with int variable stop being 6 and the int variable sum value being 0. What am I doing wrong? I am receiving no output.



for (int num = 4; num <= stop ; num++)
{
sum +=2 * num;
cout << sum << ' ';
}
Dec 14, 2009 at 3:36am
You should put up your entire code because from what I can see and if everything you say is true then this program should be working and you should be receiving output.
Dec 14, 2009 at 4:01am
I compiled it as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
	int stop = 6;
	int sum = 0;

	for (int num = 4; num <= stop ; num++)
	{
		sum +=2 * num;
		std::cout << sum << ' ';
	}

	return 0;
}


Works fine and I get the output of:
8 18 30
Dec 14, 2009 at 4:09am
So did i mythios...lol. I don't know why his is not working.
Dec 14, 2009 at 4:11am
Is your console shutting down right away to where you don't even get to see the output? Or does it just sit there doing nothing?
Topic archived. No new replies allowed.