News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Results for var are not correct

Started by Innovative101, March 19, 2010, 12:38:24 AM

Previous topic - Next topic

Innovative101

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

Seronis

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.

rcoll

The program is behaving correctly.  If you need more help, talk to your instructor. 

Ringo

Jenna

Unrelated to C::B and cross-posted = massive violation of our forum rules => topic locked !!