"Untitled Post" - Views: 784 · Hits: 784 - Type: Public

//Dont ask me what im including there, i have no idea but it works!
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
using namespace std;

int main (int argc, char *argv[])
{
    //initialises the random generator with your clocktime. Do this only once per program.            
    srand(time(NULL));
        
    int iHut;
    int iAuswahl; 
    int iTest;
    int iEingabe;
    int iSchleife;
    char cEingabe;
    char cJa = 'y';
    char cNein = 'n';
    char cPiep = 007;
    
    //this is only to generate that funny looking cup thing when you start it
    char cgeradewaagrecht = 205;
    char ceckeuntenlinks = 200;
    char ceckeuntenrechts = 188;
    char cgeradesenkrecht = 186;
    char cinhalt = 219;

    cout << "Somewhere in these 3 cups is a ball, but in which one is it?";
    
    
    for (int iSpieldauer = 0; iSpieldauer < 1;)
    {
    //random number gets generated ( 0, 1 & 2) and then we add 1 to it so we get a random number from 1 to 3
    iHut = rand()%3;
    iHut++;
    
    //only the cup-graphic-stuff
    cout << endl << endl << endl << endl << endl;
    cout << "   find the ball!" << endl << endl << endl;
    cout << "      cup 1      cup 2       cup 3" << endl << endl;
    cout << "      " << cgeradesenkrecht << cinhalt << cinhalt << cinhalt << cgeradesenkrecht; 
    cout << "      " << cgeradesenkrecht << cinhalt << cinhalt << cinhalt << cgeradesenkrecht;
    cout << "      " << cgeradesenkrecht << cinhalt << cinhalt << cinhalt << cgeradesenkrecht;
    cout << endl;
    cout << "      " << cgeradesenkrecht << cinhalt << "?" << cinhalt << cgeradesenkrecht; 
    cout << "      " << cgeradesenkrecht << cinhalt << "?" << cinhalt << cgeradesenkrecht;
    cout << "      " << cgeradesenkrecht << cinhalt << "?" << cinhalt << cgeradesenkrecht;
    cout << endl;
    cout << "      " << cgeradesenkrecht << cinhalt << cinhalt << cinhalt << cgeradesenkrecht; 
    cout << "      " << cgeradesenkrecht << cinhalt << cinhalt << cinhalt << cgeradesenkrecht;
    cout << "      " << cgeradesenkrecht << cinhalt << cinhalt << cinhalt << cgeradesenkrecht;
    cout << endl;
    cout << "      " << ceckeuntenlinks << cgeradewaagrecht << cgeradewaagrecht << cgeradewaagrecht << ceckeuntenrechts;
    cout << "      " << ceckeuntenlinks << cgeradewaagrecht << cgeradewaagrecht << cgeradewaagrecht << ceckeuntenrechts;
    cout << "      " << ceckeuntenlinks << cgeradewaagrecht << cgeradewaagrecht << cgeradewaagrecht << ceckeuntenrechts;
    cout << endl << endl;
      
    //loop to take your answer and to check if your answer is valid
    for (int iTest = 0; iTest < 1;)
    {                   
    cout << "choose a cup(1, 2 or 3):    ";
    cin >> iEingabe;
    cout << endl << endl;
    
         if (iEingabe > 3 || iEingabe < 1)
         {
         cout << "Your answer is invalid, try again.";
         cout << endl << endl; 
         }
          else
          {
          iTest++;
          }          
    }
    
    //output if you have choosen the right cup or not
    
    if (iEingabe == iHut)
    {
    cout << endl << endl;
    cout << "You have choosen the RIGHT one!" << endl;    
    cout << endl << endl;
    }
    else
    {
    cout << endl << endl;
    cout << "You have choosen the WRONG one!";
    cout << endl << endl;
    }
    
    //you get asked if you want to play again and if your input is valid
    
    do
    {
    iSchleife = 0;
     cout << endl << endl;
     cout << "Do you want to play again? Y/N" << endl;
     cin >> cEingabe;
     cout << endl << endl;
     
          if (cEingabe != cJa && cEingabe != cNein)
          {
           cout << "invalid answer, try again!";
          }
          
          if (cEingabe == cJa)
          {
           iSchleife = 1;
          }
          
          if (cEingabe == cNein)
          {
           iSchleife = 1;
           iSpieldauer = 1;
          }
     } while (iSchleife < 1);
        
    }
    getchar();
    getchar();
  return 0;
}