Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (ANSI-Standard) » wie setze ich zufallszahlen richtig ein

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
19.04.2004, 15:19 Uhr
~sbrog
Gast


in einem tutorial habe ich gelesen, dass man z.b mit


C++:
#include <windows.h>

int main()
{
randomize();
int zahl;
zahl =rand(10);
}




eine Zufallszahl erstellt.
Meine ide reagiert darauf aber nicht und schreibt ''randomize' undeclared'.
Was ist falsch ?

p.s.
ich benutze die Zufallszahl in diesem code




C++:

#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;

int main()
{
   randomize();
    cout<<"Das ist ein Wuerfelspiel\n";
    getchar();
    cout<<"Auf welche zahl tippen sie ?\n";
    
    int tippzahl;
    cin>>tippzahl;
    
    int zahl;
    zahl=rand(7)
    
    
    if (zahl==tippzahl)
    {
        cout<<"Glückwunsch, die Zahl stimmt";
    }
    
    if (zahl!=tippzahl)
    {
        cout<<"Leider falsch";
    }
    
    getchar();
  
    
}
  

 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
19.04.2004, 16:52 Uhr
Windalf
Der wo fast so viele Posts wie FloSoft...
(Operator)


probier mal so

C++:
#include <iostream>
#include <ctime>
using namespace std;

int main(){
int tippzahl;
srand(time(NULL));
cout<<"Das ist ein Wuerfelspiel\n";
cout<<"Auf welche zahl tippen sie ?\n";
cin>>tippzahl;
if (tippzahl==1+rand()%6) //zahl von 1 bis 6
cout<<"Glückwunsch, die Zahl stimmt";
else  cout<<"Leider falsch";
}


--
...fleißig wie zwei Weißbrote
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
19.04.2004, 17:05 Uhr
~oundo
Gast


das was du gemacht hattest hatte mit alten turbo c++ compilern funktioniert!
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
19.04.2004, 17:31 Uhr
Pablo
Supertux
(Operator)


Das funktioniert mit einem Compiler, der ANSI C++ kompilieren kann.
--
A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (ANSI-Standard) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: