codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
// Profil erstellen // #include <iostream> #include <Windows.h> using namespace std; #pragma comment (lib, "winmm.lib") // Strukturen // struct S_Player { char ch_Name[30]; // 1 char ch_Slogan[50]; // 2 }; // Variablen // S_Player Player1; S_Player Player2; int main () { // Zufallsgenerator srand (timeGetTime ()); // Prototypen // void header(); void game(); // Spielerdaten 1 // system("CLS"); header(); cout << "\t[SPIELER 1] Name: "; cin.get (Player1.ch_Name, 29); cin.ignore(); cout << "\t[SPIELER 1] Slogan: "; cin.get (Player1.ch_Slogan, 49); cout << endl; system("PAUSE"); cin.ignore(); // Spielerdaten 2 // system("CLS"); header(); cout << "\t[SPIELER 2] Name: "; cin.get (Player2.ch_Name, 29); cin.ignore(); cout << "\t[SPIELER 2] Slogan: "; cin.get (Player2.ch_Slogan, 49); cout << endl; system("PAUSE"); cin.ignore(); // Alle Daten auflisten system("CLS"); header(); cout << "\t1. " << Player1.ch_Name << ", " << Player1.ch_Slogan << endl; cout << "\t2. " << Player2.ch_Name << ", " << Player2.ch_Slogan << endl; cout << endl; system("PAUSE"); game(); return 0; } void header() { cout << "\n\tZAHLENRATEN 1ON1\n\t----------------->\n\n"; // Profil 1 } void game() { // Variablen int n_Random; // Zufallszahl die erraten werden muss int n_Guessed_P1 = 0; // Geratene Zahl int n_Guessed_P2 = 0; // Geratene Zahl int n_Range = 100; // Zahlenbereich int n_Try_P1 = 0; // Anzahl der Versuche int n_Try_P2 = 0; // Anzahl der Versuche int n_TryDiff_P1 = n_Try_P2 - n_Try_P1; int n_TryDiff_P2 = n_Try_P1 - n_Try_P2; // Zufallszahl ermitteln n_Random = (rand()%n_Range+1); system("CLS"); header(); cout << "\t>> " << Player1.ch_Name << " ist an der Reihe!\n"; cout << "\t>> Zahlenbereich: 1 bis 100\n\n"; while (n_Guessed_P1 != n_Random) { cout << endl; cout << "\t>> Dein Tipp: "; cin >> n_Guessed_P1; n_Try_P1++; if (n_Guessed_P1 < n_Random) { cout << endl; cout << "\t>> G R O E S S E R !" << endl; } if (n_Guessed_P1 > n_Random) { cout << endl; cout << "\t>> K L E I N E R !" << endl; } } // Zahl wurde erraten cout << endl; cout << "\t>> G E S C H A F F T !" << endl; cout << "\t>> " << Player1.ch_Name << " benoetigte " << n_Try_P1 << " Versuche!" << endl; system("PAUSE"); // DAS SELBE FUER SPIELER 2 // Neue Zufallszahl n_Random = (rand()%n_Range+1); system("CLS"); header(); cout << "\t>> " << Player2.ch_Name << " ist an der Reihe!\n"; cout << "\t>> Zahlenbereich: 1 bis 100\n\n"; while (n_Guessed_P2 != n_Random) { cout << endl; cout << "\t>> Dein Tipp: "; cin >> n_Guessed_P2; n_Try_P2++; if (n_Guessed_P2 < n_Random) { cout << endl; cout << "\t>> G R O E S S E R !" << endl; } if (n_Guessed_P2 > n_Random) { cout << endl; cout << "\t>> K L E I N E R !" << endl; } } // Zahl wurde erraten cout << endl; cout << "\t>> G E S C H A F F T !\n\n" << endl; cout << "\t>> " << Player2.ch_Name << " benoetigte " << n_Try_P2 << " Versuche!" << "\n\n\n"; system("PAUSE"); system("CLS"); header(); cout << "\t>> S I E G E R:" << endl; if (n_Guessed_P1 < n_Guessed_P2) // WENN Spieler1 weniger Versuche benötigt hat { cout << "\t>> " << Player1.ch_Name << " hat gewonnen!" << endl; cout << "\t>> " << Player2.ch_Name << " benoetigte " << n_TryDiff_P1 << " mehr Versuche!" << endl; } else { cout << "\t>> " << Player2.ch_Name << " hat gewonnen!" << endl; cout << "\t>> " << Player1.ch_Name << " benoetigte " << n_TryDiff_P2 << " mehr Versuche!" << endl; } cout << endl; cout << endl; system("PAUSE"); }
Private
[
?
]
Run code
Submit