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

Pages: 1-

C++ Creating Functions question

Name: Wut? 2013-09-30 20:05

I'm attempting to create a DnD stat generator. I've created a function previous to the one I'm about to post that I didn't have any trouble with, but this one doesn't want to work.

int mod(x)
{

    int x1;

    if ( x == 18 )
        x1 = 4;

        //Yadayada if else statements

    return x1;
}

int main (void)
{
    srand(time(NULL));

    int x[6];

    for (int i = 0; i < 5; i++)
    {
        x[i] = roll();
    }

    for ( int i = 0, x1 = 0, x2 = 0; i < 5; i++)
    {
        cout << x[i] << " " <<
        x1 = x[i];
        x2 = mod(x1); // This being where I have trouble
                              // Function just doesn't want to run
        if ( x2 >= 1 )
            cout << "+" << x2 << endl;
        else
            cout << x2 << endl;
    }



    return 0;

}

Name: Anonymous 2013-09-30 20:07

read SICP

Name: Anonymous 2013-09-30 20:13

Read all five chapters of Structure and Interpretation of Computer Programs.

Name: Anonymous 2013-09-30 20:14

    '-._                  ___.....___
        `.__           ,-'        ,-.`-,            Have you read your SICP today?
            `''-------'          ( p )  `._      
                                  `-'      \
                                            \
                                  .         \
                                   \---..,--'
       ................._           --...--,
                         `-.._         _.-'
                              `'-----''

Name: Anonymous 2013-09-30 20:21

Rewrite it in Haskell

Name: Anonymous 2013-09-30 20:28

install gentoo

Name: Anonymous 2013-09-30 20:44

use perl and read the camel book

Name: Anonymous 2013-09-30 21:09

C++ is a horrible language. It's made more horrible by the fact that a lot
of substandard programmers use it, to the point where it's much much
easier to generate total and utter crap with it. Quite frankly, even if
the choice of C were to do *nothing* but keep the C++ programmers out,
that in itself would be a huge reason to use C.

In other words: the choice of C is the only sane choice. I know Miles
Bader jokingly said "to piss you off", but it's actually true. I've come
to the conclusion that any programmer that would prefer the project to be
in C++ over C is likely a programmer that I really *would* prefer to piss
off, so that he doesn't come and screw up any project I'm involved with.

C++ leads to really really bad design choices. You invariably start using
the "nice" library features of the language like STL and Boost and other
total and utter crap, that may "help" you program, but causes:

 - infinite amounts of pain when they don't work (and anybody who tells me
   that STL and especially Boost are stable and portable is just so full
   of BS that it's not even funny)

 - inefficient abstracted programming models where two years down the road
   you notice that some abstraction wasn't very efficient, but now all
   your code depends on all the nice object models around it, and you
   cannot fix it without rewriting your app.

In other words, the only way to do good, efficient, and system-level and
portable C++ ends up to limit yourself to all the things that are
basically available in C. And limiting your project to C means that people
don't screw that up, and also means that you get a lot of programmers that
do actually understand low-level issues and don't screw things up with any
idiotic "object model" crap.

Name: Anonymous 2013-09-30 21:56

dnd? isnt that a game for nerds?

Name: Anonymous 2013-10-01 5:54

>>9
It used to be. D&D is quite mainstream nowadays. I caught a couple of chaps rolling dice at a frat party once.

Name: Anonymous 2013-10-01 6:00

roll();

Name: Anonymous 2013-10-01 15:18

check_em(11);

Name: Anonymous 2013-10-01 17:23

Why aren't you passing by reference?
Why your x[5] doesn't get roll()?
Why are you cout for integers?

Name: Anonymous 2013-10-01 17:27

>>13
Also, what is your type of parameter in your sum function?

Name: Anonymous 2013-10-01 17:49

`>Hakase! Hakase! Hakase! Hakase!
`>Nano! Nano! Nano! Nano!

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