Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.30 KB | None | 0 0
  1. #!/bin/perl
  2.  
  3. $switch=1;
  4. $nochmal=1;
  5.  
  6. sub limit
  7. {
  8.   print "Hoechste Zahl? ";
  9.   $max=<STDIN>;
  10.   chomp $max;
  11.   return $max;
  12. }
  13.  
  14. sub ran
  15. {
  16.   $ran=int(rand($max));
  17. }
  18.  
  19. sub eingabe
  20. {
  21.   while ($switch!=0)
  22.   {
  23.     print "Ihre Zahl: ";
  24.     $user_input=<STDIN>;
  25.     chomp $user_input;
  26.  
  27.     if ($user_input =~ /^[a-zA-zöäüÖÄÜ]*$/)
  28.     {
  29.       print "Keine Zahl!\n";
  30.     }
  31.     elsif ((length($user_input)) > 2)
  32.     {
  33.       print "Zahl zu groß!\n";
  34.     }
  35.     elsif ($user_input<$ran)
  36.     {
  37.       print "Gesuchte Zahl ist größer.\n";
  38.     }
  39.     elsif ($user_input>$max)
  40.     {
  41.       print "Zahl größer als Maximalwert!\n";
  42.     }
  43.     elsif ($user_input>$ran)
  44.     {
  45.       print "Gesuchte Zahl ist kleiner,\n";
  46.     }
  47.     elsif ($user_input==$ran)
  48.     {
  49.       print "Treffer!\n";
  50.       $switch=0;
  51.     }
  52.   }
  53. }
  54.  
  55. sub nochmal
  56. {
  57.   print "Nochmal? (j/n)";
  58.   $user_input2=<STDIN>;
  59.   chomp $user_input2;
  60.  
  61.   if ($user_input2 eq 'j' or $user_input2 eq 'j')
  62.   {
  63.     $nochmal=1;
  64.     $switch=1;
  65.     return $nochmal;
  66.  
  67.   }
  68.   elsif ($user_input2 eq 'n' or $user_input2 eq 'N')
  69.   {
  70.     $nochmal=0;
  71.     return $nochmal;
  72.   }
  73.   else
  74.   {
  75.     print "Ungültige Eingabe";
  76.     $nochmal=0;
  77.     return $nochmal;
  78.   }
  79. }
  80.  
  81. while ($nochmal==1)
  82. {
  83. &limit;
  84. &ran;
  85. &eingabe;
  86. &nochmal;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement