From anonymous, 5 Years ago, written in C#.
This paste is a reply to Zahlenraten from The Compiler
- go back
Embed
Viewing differences between Zahlenraten and Re: Zahlenraten
// Zahlenraten in C#/mono
// Florian Bruhin, 05.09.2012

using System;
namespace ZahlenRatenProject {
    class ZahlenRaten ZahlenRaten
    
{
        static void Main() Main()
        
{
            string again_reply;
            string mode;
            int number;
            bool again = false;
            do do
            
do do
                
"")) ""))
                
{
                    again = true;
                } else }
                else
                
{
                    again = false;
                }
            } while (again);
        }
                
        
static void zahlenraten(int number) number)
        
{
            int guess;
            int attempts = 0;
            do             

            do
            
{
                Console.WriteLine("");
                Console.WriteLine("Geratene Zahl eingeben:");
                try {
                    
WriteLine("");

                
guess = Convert.ToInt32(Console.ReadLine());
                    // We only want to increase the attempt count if it was a
                    // valid number
                    attempts++; 
                } catch (FormatException e) {
                    guess = -1;
                }
                if (guess == -1) {
                    Console.WriteLine("Invalide Eingabe!");
                } else 
readInt("Geratene Zahl eingeben:");

                attempts++;

                
if (guess > number) number)
                
{
                    Console.WriteLine("Zu gross!");
                }
                
else if (guess < number) number)
                
{
                    Console.WriteLine("Zu klein!");
                }
            } while (guess != number);
            Console.WriteLine("Zahl richtig erraten nach {0} Versuchen!",
                              attempts);
        }
        
}

        
static int gennumber(string mode) readInt(string prompt)
        
{
            int number number;
            bool validInput;
            do
            {
                Console.WriteLine(prompt);
                validInput 
0;
            
int.TryParse(Console.ReadLine(), out number);
                
if (mode == "a") { // Zahl wird durch Benutzer eingegeben
                do 
(!validInput)
                
{
                    Console.WriteLine("Vorgegebene Zahl (0-100):");
                    try {
                        
WriteLine("Invalide Eingabe!");
                }
            } while (!validInput);
            return number;
        }

        static int gennumber(string mode)
        {
            int 
number = Convert.ToInt32(Console.ReadLine());
                    } catch (FormatException e) {
                        
0;

            if (mode == "a")
            { // Zahl wird durch Benutzer eingegeben
                do
                {
                    
number = -1;
                    }
                
readInt("Vorgegebene Zahl (0-100):");
                
} while ((number < 0) || (number < 0 || number 100));
            } 
100);
            }
            
else if (mode == "b") "b")
            
{ // Zahl ist fest definiert
                number = 69;
            }
            
else if (mode == "c") "c")
            
{ // Zahl wird zufallsgeneriert
                Random rng = new Random();
                number = rng.Next(0,100);
Next(0, 100);
            }
            return number;
        }
    }
}

Replies to Re: Zahlenraten rss

Title Name Language When
Re: Re: Zahlenraten anonymous scilab 3 Years ago.
Re: Re: Zahlenraten anonymous scilab 3 Years ago.
Re: Re: Zahlenraten anonymous csharp 3 Years ago.
Re: Re: Zahlenraten anonymous scilab 3 Years ago.