Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C++ assist

Name: C++ Noob 2010-09-23 23:58

Ok so I am learning C++ and I suck.

Trying to add 1/1 + 1/2 + ... + 1/99 + 1/100

The problem is I can't get the denominator to increase as I attempt to add them.
Anyone care to point out my most likely obvious mistake?

This is what I have


#include <iostream>

using namespace std;

void main ()
    {
    const    long    MaxNum (100);
    double    i;
    double    Sum;
    double    x;
    for (x = 1, i = 1/1, Sum = 0; x <= MaxNum; x++)
        Sum += i;
    cout << "Sum is " << Sum << endl;
}

Name: Anonymous 2010-09-24 0:18

That code is pathetic, even for someone who's never programmed before. It's impressive when the least of its problems is that it's in Sepples.
Start over.

Name: Anonymous 2010-09-24 0:19


...
...
Sum = 0;
for (x = 1; x <= MaxNum; x++)
   Sum += 1/x;
...
...

Name: Anonymous 2010-09-24 0:32

>>3
Why did you move the Sum = 0; out of the for declaration? Is it because you don't understand the comma operator?

Name: Anonymous 2010-09-24 0:49

>>4
If that is all you are complaining about, then there is nothing to complain about.

Name: Anonymous 2010-09-24 0:58

>>4
Not really. Is just that i like it that way. Easier to read IMO.

Name: Anonymous 2010-09-24 1:59

>>4

Sum = 0;
x = 1;
for (;;)
{
 Sum += 1/x;
 x++;
 if (x > MaxNum)
   break;
}

ENTERPRISE QUALITY READABILITY

Name: Anonymous 2010-09-24 4:12

>>7
ENTERPRISE programmers don't program like that. Only faggots trying to be clever do that.

Name: Anonymous 2010-09-24 7:43

ENTERPRISE PRODUCTION PSEUDOCODE

public class PerformOperation {
    EnterpriseRealNumber ReallyPerform() {
        EnterpriseRealNumber ernSum = new EnterpriseRealNumber(0);
        EnterpriseRealNumber ernX = new EnterpriseRealNumber(1);
        EnterpriseRealNumber ernMaxNum;
        ernMaxNum = MaximumNumberForOperationSingletonPattern.getInstance().getMaximumNumberForOperation(new OperationConfirmer(new EnterpriseBoolean(1));

        for (new EnterpriseDummyValue(); ernX.comparesLessOrEqualsTo(ernMaxNum); ernX.performNumericOperation(new NumericOperation(new OperationIncrementDescriptor(new EnterpriseRealNumber(1))))) {
            ernSum.performNumericOperation(new NumericOperation(new OperationAdditionDescriptor(new EnterpriseRealNumber(1).performNumericOperation(new NumericOperation(new OperationDivisionDescriptor(ernX))))));
        }
        return ernSum;
    }
}

Name: Anonymous 2010-09-24 10:14

>>7
The only reason to use a break or continue statement is if you really can't guarantee contents or the duration of a loop iteration.  On the other hand, encountering a situation like this suggests you might reconsider how you are trying to accomplish what you are doing.

Name: Anonymous 2010-09-24 10:30


#include <stdio.h>

int main(void)
{
    register long max = 100;
    register double i, x, sum = 0;
    for (i=x=1.0; x <= max; ++x)
        sum += i/x;
    printf("%s %g/n","sum is:",sum);
}

Name: Anonymous 2010-09-24 11:02

my @denom=1..100; my @results = 1 <</>> @denom; say [+]@results;

try.rakudo.org

Name: Anonymous 2010-09-24 11:41

C++ PROGRAMMERS ARE ALL RETARDS. I HATE C++ PROGRAMMERS SO MUCH. I LOL AT HOW THEY MAKE THINGS PRIVATE IN CLASSES BUT THEY ARE CLASSES THAT THEY ARE JUST USING THEMSELVES. STOP BEING A FAG. DONT THEY TRUST THEMSELVES>??? OOOOH IVE GOT TO PROTECT THE VARIABLSE.

FUCK U C++. I AM A SUPER COOL PROGRAMMER AND I CAN HANDLE HAVING ACCESS TO EVERYTHING I AM USING. IF IM NOT MEANT TO USE IT, I WONT. IM NOT SOME FAG THAT CANT BE TRUSTED AND HAVE TO HAVE THE PRIVACY ENFORCED. ENJOY YOUR WASTED HOURS WRITING GET AND SET METHODS FAG WHILE IM WRITING AMAZING CODE AND HAVING SEX WITH MODELS AND SNORTING COCAINE OFF THEIR TITS.

Name: Anonymous 2010-09-24 11:48

>>12

say [+] 1 <</>> (1..100);

I win, fag

Name: Anonymous 2010-09-24 11:59

>>13
#define private public

Name: Anonymous 2010-09-24 12:06

>>13
this is copypasta. i can tell from having written this text last year sometime

Name: Anonymous 2010-09-24 12:13

>>16
Thanks Sherlock. Now I have another case where I have to rely on your special abilities...

Name: VIPPER 2010-09-24 12:15

>>16
dude, give me some of that coke.

Name: Anonymous 2010-09-24 13:04

>>17
where is original thread

Name: Anonymous 2010-09-24 15:07

>>13,15-19
It may be an old troll, but as a C++ asshole, I have to admit that this thought crosses my mind pretty often.

"Ok, why am I making this private again?  Am I afraid I'll accidentally become an idiot in the near future?"

And if I did decide that I really needed to touch that forbidden piece of data, would private really stop me?  Wouldn't a comment along the lines of

// Hey shithead, this is internal state that gets updated by this other method over here, so why don't you call that instead?

be more helpful?

Name: Anonymous 2010-11-27 19:34

Name: Anonymous 2010-12-09 4:20

Name: Anonymous 2011-02-03 0:38

Don't change these.
Name: Email:
Entire Thread Thread List