[text] 17.1

Viewer

  1. /**********************************************************************\
  2. * Kurzbeschreibung: Übung 16.1
  3. *
  4. * Datum:       Autor:        Grund der Aenderung:
  5. * 12.02.21     Heiko Kastner
  6. *
  7. \**********************************************************************/
  8.  
  9. /*--- #includes ------------------------------------------------------*/
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <math.h>
  13. #include <cstdlib>
  14. #include <iomanip>
  15. #include <ctype.h>
  16. /*--- #defines -------------------------------------------------------*/
  17.  
  18. /*--- typedef-Datentypen ---------------------------------------------*/
  19.  
  20. /*--- Funktionsdefinitionen ------------------------------------------*/
  21. int main()
  22. {
  23.     int z,y,i;
  24.     i= 0;
  25.     printf("Zunaechst musst du einmal festlegen, wie gross die zu ratende Zahl \n"
  26.            "maximal sein darf:\n");
  27.     scanf("%d",&z);                                                              //Belegung der Variable//
  28.  
  29.  
  30.     if (isdigit(z)){
  31.  
  32.         int t = rand () %z + 1 ;                                                //Generieren des Zufallswertes mit z+1 -----> Null ausgeschlossen//
  33.         printf("Hm ..... OK, ich habe eine Zahl\n");
  34.  
  35.         do
  36.         {
  37.             // Hochzählen der Rateversuche
  38.             i+=1;
  39.             printf("Dein %d. Versuch:",i);
  40.             scanf("%d",&y);
  41.             if(y < t)
  42.                 printf("                       .....zu niedrig \n");            // Fehlerbedingungen für zu groß und zu klein
  43.             else if
  44.  
  45.             (y > t)
  46.                 printf("                       ........zu hoch \n");
  47.         }
  48.         while(y!= t);
  49.     }
  50.     else{
  51.         printf("Ungueltige Eingabe !!\n");
  52.         return 0;
  53.     }
  54.  
  55.  
  56.  
  57.  
  58.     printf("                       ........richtig \n");
  59.  
  60.  
  61.     printf("Du hast %d. Versuche zum erraten der Zahl benoetigt\n",i);
  62.  
  63.  
  64.     return 0;
  65.  
  66. }
  67.  
  68.  

Editor

You can edit this paste and save as new:


File Description
  • 17.1
  • Paste Code
  • 12 May-2021
  • 1.87 Kb
You can Share it: