Function returning true/false instead of value

I'm trying to write a function that will generate a 1 or a 2, and the number using that function, in main.

Instead of printing the number, it just prints "1" and gives me the error "Address of function 'OneOrTwo' will always evaluate to 'true'.

I don't get it...
I'm not trying to generate a boolean value, but an integer...

1
2
3
4
5
6
7
8
9
10
11
12
int OneOrTwo() {
    srand (time(NULL));
    int number = rand() % 2+1;
    return number;
};

main() {

cout << OneOrTwo << endl;

}
Last edited on
closed account (18hRX9L8)
You are missing an ending curly-brace for the starting one at line 1.
Last edited on
Fixed, but that's not the problem.
This might help you out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>
using namespace std;
int OneOrTwo(int& number) {
    srand (time(NULL));
    number = rand() % 2+1;
    return number;
}
int main() {
	int number;
	OneOrTwo(number);

cout << number << endl;

system("PAUSE");
return 0;
}
Last edited on
Ahh, all I needed were the parentheses at the end of the OneOrTwo when printing.
Thanks, solved.
Topic archived. No new replies allowed.