Author Topic: Results for var are not correct  (Read 3594 times)

Offline Innovative101

  • Single posting newcomer
  • *
  • Posts: 2
Results for var are not correct
« 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

Offline Seronis

  • Almost regular
  • **
  • Posts: 197
Re: Results for var are not correct
« Reply #1 on: March 19, 2010, 01:28:36 am »
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.

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Results for var are not correct
« Reply #2 on: March 19, 2010, 07:48:15 am »
The program is behaving correctly.  If you need more help, talk to your instructor. 

Ringo

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Results for var are not correct
« Reply #3 on: March 19, 2010, 08:44:26 am »
Unrelated to C::B and cross-posted = massive violation of our forum rules => topic locked !!