Code::Blocks Forums
User forums => Help => Topic started by: Innovative101 on March 19, 2010, 12:38:24 am
-
I am typing the following simple for loop into codeblocks and getting 5050 instead of 1 through 100
#include <iostream>
using namespace std;
int main()
{
int x = 0;
int i;
for (i = 1; i <= 100; i++)
{
x += i;
}
cout << x << endl;
return 0;
}
great compiler if it works! I need some answers pronto is there anybody there that can get me going in the right direction
-
1. you only have 1 printing statement so only getting one output is correct behaviour.
2. the sum of all values from 1 to 100 (what your program does) *IS* 5050 so that is correct behaviour
3. (the important one) THIS HAS NOTHING TO DO WITH USING CODEBLOCKS AS AN IDE and thus violates the forum rules for posting here.
i recommend you download an irc client and go to #C++-Basic or ANY OTHER place on the internet that actually teaches coding. This forum does not and this topic WILL get locked as soon as an admin sees it for this very reason.
-
The program is behaving correctly. If you need more help, talk to your instructor.
Ringo
-
Unrelated to C::B and cross-posted = massive violation of our forum rules => topic locked !!