Bitte um hilfe..!
-
Ich bereite gerade für eine Klausur vor, aus einer MusterKlausur hab ich dieses Programm erzeugt nur bekomm ich ein Fehler angezeigt was ich nicht nachvollziehen konnte..hoffe einer kann mich aufklären
Programm:
#include <cstdlib>
#include <iostream>
#include <conio.h>using namespace std;
class Roulette
{
public:
Roulette(int anz)
{
anzahl = anz;
zahlen = new int[anzahl];
for (int i = 0; i < anzahl; i++)
{
zahlen [i] = random(37); // hier erzeugt er ein Fehler ?!?!?!
}
}void auswerten();
void ausgeben();
~Roulette() {delete[] zahlen;}private:
int *zahlen;
int anzahl;
int gerade;
int rot;
static int rotZahlen[18];
int eZahl[37];
};int Roulette::rotZahlen[] = {1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36};
void Roulette::auswerten()
{
rot = 0;
gerade = 0;
for (int i = 0; i < 37; i++) {eZahl[i] = 0; }
for (int i = 0; i < anzahl, i++)
{
eZahl[zahlen[i] ]++;
if (zahlen [i] %2 == 0 && zahlen[i] > 0 {gerade++;}
for (int j = 0; j < 18; j++)
{
if ( zahlen[i] == rotZahlen[j]) {rot++;}
}
}
}void Roulette::ausgeben()
{
cout << "Es wurden " << anzahl << "Zahlen erzeugt." << endl;
for (int i = 0; i < 37; i++)
{
cout << eZahl[i] << ends;
}
cout << endl;
cout << "Gerade: " << ends << gerade << endl;
cout << "rot: " << ends << rot << endl;
}int main(int argc, char *argv[])
{
Roulette MonteCarlo(1000);
MonteCarlo.auswerten();
MonteCarlo.ausgeben();system("PAUSE");
return EXIT_SUCCESS;
}Fehler:
15 C:\Dokumente und Einstellungen\Gabriele\Desktop\C++\21tagec++\test_20_05.cpp `random' undeclared (first use this function)
-
Wie der Fehler schon sagt, wird die Funktion random nicht gefunden. Die Funktion, die du suchst dürfte rand(...) sein.
Gruss,
DeSoVoDaMu
-
Hi. Ich glaube random ist keine Standard-Funktion... Bei Borland gibts das als Makro in der stdlib.h. Kannst du aber auch selber definieren:
#define random(__num) (__num ? (int)(_lrand()%(__num)) : 0)
Oder besser eine eigene kurze Funktion:
inline int random(int const& min, int const& max) { return ( rand() % ( max - min + 1 ) ) + min; }