Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- $switch=1;
- $nochmal=1;
- sub limit
- {
- print "Hoechste Zahl? ";
- $max=<STDIN>;
- chomp $max;
- return $max;
- }
- sub ran
- {
- $ran=int(rand($max));
- }
- sub eingabe
- {
- while ($switch!=0)
- {
- print "Ihre Zahl: ";
- $user_input=<STDIN>;
- chomp $user_input;
- if ($user_input =~ /^[a-zA-zöäüÖÄÜ]*$/)
- {
- print "Keine Zahl!\n";
- }
- elsif ((length($user_input)) > 2)
- {
- print "Zahl zu groß!\n";
- }
- elsif ($user_input<$ran)
- {
- print "Gesuchte Zahl ist größer.\n";
- }
- elsif ($user_input>$max)
- {
- print "Zahl größer als Maximalwert!\n";
- }
- elsif ($user_input>$ran)
- {
- print "Gesuchte Zahl ist kleiner,\n";
- }
- elsif ($user_input==$ran)
- {
- print "Treffer!\n";
- $switch=0;
- }
- }
- }
- sub nochmal
- {
- print "Nochmal? (j/n)";
- $user_input2=<STDIN>;
- chomp $user_input2;
- if ($user_input2 eq 'j' or $user_input2 eq 'j')
- {
- $nochmal=1;
- $switch=1;
- return $nochmal;
- }
- elsif ($user_input2 eq 'n' or $user_input2 eq 'N')
- {
- $nochmal=0;
- return $nochmal;
- }
- else
- {
- print "Ungültige Eingabe";
- $nochmal=0;
- return $nochmal;
- }
- }
- while ($nochmal==1)
- {
- &limit;
- &ran;
- &eingabe;
- &nochmal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement