Spiel Heiß oder Kalt
Homepage
Spiel Kalt oder Heiß¶
https://trainyourprogrammer.de/cplusplus-283-game---hei%C3%9F-oder-kalt.html
include the mbed library with this snippet
#include <iostream>
#include "time.h"
using namespace std;
int main()
{
time_t now;
time_t final;
double seconds;
int Eingabe;
int ZahlFix;
int Versuche=0;
cout << "Geben Sie ein Zahl ein: ";
cin >> ZahlFix;
system("CLS");
if (ZahlFix >= 1 && ZahlFix <= 10)
{
time(&now);
do
{
cout << "Versuchen Sie jetzt:";
cin >> Eingabe;
Versuche++;
if (Eingabe+1 == ZahlFix|| Eingabe - 1 == ZahlFix)
{
cout << "Falsch! Heiss!" << endl << endl;
}
else if (Eingabe+2 == ZahlFix || Eingabe - 2 == ZahlFix)
{
cout << "Falsch! Warm!" << endl << endl;
}
else if (Eingabe == ZahlFix)
{
time(&final);
seconds = difftime(final, now);
cout << endl << "Genau ! Zeit: " << seconds << " sekunden" << endl << "Versuche: " << Versuche << endl;
}
else
{
cout << "Falsch! Kalt!" << endl << endl;
}
} while (Eingabe != ZahlFix);
}
else
{
cout << "Wahlen Sie ein Zahl zwichen 1 und 10!"<<endl;
}
}