-2

I want to create a little game in c++, and therefore I need a function to return random numbers in a specific range.

Most of the answers I found were similar to this one https://stackoverflow.com/a/19728404/5780938, and I think this is the solution I'm looking for.

To test if the function does, what I want it to, I tried outputting the results in several different ways.

At the moment my code looks like this:

#include "stdafx.h"
#include <iostream> 
#include <random>


int zufälligeZahl();

int main()
{
using std::cin;
using std::cout;

cout << zufälligeZahl << "\n";
cout << zufälligeZahl << "\n";
cout << zufälligeZahl << "\n";
cout << zufälligeZahl << "\n";

return 0;
}

int zufälligeZahl()
{
std::random_device rd;
std::mt19937 zGenerator(rd());
std::uniform_int_distribution<int> uni(1, 13);

int random_integer = uni(zGenerator); 

return random_integer; 
} 

I've tried this in many different ways, but no matter what I do, it doesn't work. Either the output is something like 00A8106E, or I don't get any output at all.

I'm using Visual Studio Community 2015.

Community
  • 1
  • 1
Andy
  • 21
  • 1
  • 4

1 Answers1

2

You are not calling the function zufälligeZahl, you are printing out the address of the function. Fix your code by actually calling the function:

 cout << zufälligeZahl() << "\n";

You forgot the parentheses.

kat0r
  • 949
  • 8
  • 17
  • Oh, damn, that was a stupid mistake :(. The weird thing is, that I actually tried copying solutions from different websites, and it still didn't work. I guess that got me even more confused. Thank you very much for your answer! – Andy Mar 19 '16 at 18:55