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

compiler/callfunction

Name: Anonymous 2010-11-05 22:55

Hurr, getting into the basics of C++ here, and running into issues with calling user defined functions more often that I feel I should. I wrote a mock program to test the issue, and I'm still running into trouble:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;
int randGen ();

int main ()
{
    srand ( time ( 0 ) );
    cout << randGen;
    cin.ignore().get();
    return EXIT_SUCCESS;
}

int randGen ()
{
    srand ( time ( 0 ) );
    return ( 1 + rand ( ) % 10);
}

It compiles, but it tells me "[Warning] the address of `int randGen()', will always evaluate as `true' " and the only thing it outputs is "1" when I want it to output a random number between 1 and 10.

help?

Name: Anonymous 2010-11-05 23:40

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
int randGen ();

int main ()
{
    cout << randGen();
    return 0;
}

int randGen ()
{
    srand ( time(NULL) );
    return ( 1 + rand ( ) % 10);
}

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