I am using modulus 6 plus 1 on rand() to generate numbers from 1 to 6 through a function call. But the function returns 004111E5. I don't know why the rand() doesn't behave the way it should once it is in another function. Can someone enlighten me please? I am using Visual Express 2010. The following is the code. Thank you.
#include "iostream"
#include "cstdio"
using namespace std;
int rand_num(int); // Prototype for the rand() function within another function
int main()
{
cout << rand_num << endl;
return 0;
}
int rand_num(int numX) // rand() function in another function named rand_num()
{
numX = rand() % 6 + 1;
#include <iostream> // angle braces
#include <cstdio>
usingnamespace std;
int rand_num(); // Note, no parameter
int main()
{
cout << rand_num() << endl; // use () to call the function rather than use its address.
return 0;
}
int rand_num() // rand() function in another function named rand_num()
{
int numX; // declare this here, NOT as a parameter.
numX = rand() % 6 + 1;
return numX;
}
I spent 3 hours trying to understand what I'm doing wrong. So address [without ()] vs value [with ()], I got it.
So square brackets for the header files? Some of my Visual Express 2010 had it in double quotation marks and did not take in the square brackets, so I thought that people are switching from one practice to another. Thanks for the help, both of you.