Einzelnen Beitrag anzeigen
Ungelesen 13.09.09, 14:48   #10
Underkane
Ist öfter hier
 
Benutzerbild von Underkane
 
Registriert seit: Aug 2008
Beiträge: 232
Bedankt: 26
Underkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt PunkteUnderkane leckt gerne myGully Deckel in der Kanalisation! | 1630841 Respekt Punkte
Standard

Stand der Dinge:
Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(void)


{
   
    cout << "Hallo! "; //Begrüßung Anfang
    cout << "Ich will mit dir ein Spiel spielen." << endl;
    cout << "Ich denke mir eine Zahl zwischen 1 und 10. " << endl;
    cout << "Du musst herauszufinden, welche Zahl ich mir gedacht habe." << endl;
    cout << "Los geht's! Du hast 11 Versuche! *grins*" << endl; //Begrüßung Ende
    cout << "" << endl; //Leere Zeile
    cout << "(c) by Andreas Schmidt" << endl; //copyright =)
    cout << "" << endl; //Leere Zeile

    int ZahlenBereich = 10;
    int gesucht = rand()%ZahlenBereich+1;
    int zahl;
    
    cout << "Welche Zahl habe ich mir gedacht? ";
    
    
	bool gefunden = false;
	while (! gefunden) {
		cin >> zahl;
		if (zahl == gesucht) {
			gefunden = true;
			cout << "" << endl;
			cout << "Richtig!" << endl;
			cout << "" << endl;
			system("PAUSE"); //schließen
            return EXIT_SUCCESS;
		}
		else if(zahl > 10)
        {
            cout << "" << endl; 
            cout << "Du willst doch nicht etwa Schummeln, oder!?" << endl << "Versuch' es nochmal: "; 
		}
		else if(zahl < 1)
        {
            cout << "" << endl; 
            cout << "Du willst doch nicht etwa Schummeln, oder!?" << endl << "Versuch' es nochmal: "; 
		}
		
		else
        {
            cout << "" << endl; 
            cout << "Leider falsch!" << endl << "Versuch' es nochmal: "; 
		}
	}
}
Alles funktioniert.
Nun möchte ich aber, dass die Zahl zufällig generiert wird. Richtig zufällig muss sie nicht sein, sie kann auch nach einem bestimmten Schema generiert werden, aber man sollte das "Spiel" mindestens 3-4x aufrufen können ohne dass die Zahl doppelt vorkommt.

Und am besten soll noch ausgegeben werden ob die gesuchte Zahl größer oder kleiner ist als die eingegebe Zahl.
__________________
Underkane ist offline   Mit Zitat antworten