Occasionally bored, wrote the number of sheep programs to tease themselves
Introduction: Enter an integer to count the sheep
Approximate flowchart:
Effect:
The code is as follows:
1 class Program2 {3 Static voidMain (string[] args)4 {5 GetNumber ();6 Console.readkey ();7 } 8 Public Static voidGetNumber ()9 {Ten BOOLExit =false; OneConsole.WriteLine ("Please input moutons number:"); A stringinput =console.readline (); - intn =-1; - while(true) the { - if(int. TryParse (Input, outn) && n >0) - { - if(n>=5) Break; + if(n==1) -Console.WriteLine ($"Only {n}, is you kidding me? I don ' t count ..."); + Else AConsole.WriteLine ($"I don ' t Count...jajajajaja ..."); at } - Else -Console.WriteLine ("rules:moutons number should be greater than 0."); -Console.WriteLine ("Please input moutons number again or input ' exit ' Go to sleep:"); -input =console.readline (); - if(Input. Trim () = ="Exit") in { -Exit =true; to Break; + } - } the if(!exit) * Clock (n); $ ElsePanax Notoginseng Msg (); - } the Public Static voidClock (intN) + { A inti =1; the while(i<=N) + { -Console.WriteLine ($"{i} only moutons: ZZZ"); $i++; $Thread.Sleep ( -); - } -Console.WriteLine ("Bonne nuit, les moutons comptent."); the Msg (); - }Wuyi Public Static voidMSG () the { - intnow =DateTime.Now.Hour; Wu if(Now <5) - { AboutConsole.WriteLine ($"It ' s {now} o ' clock in the morning,you should go to bed."); $ } - Else if(Now < A) - { -Console.WriteLine ("Good morning."); A } + Else if(Now < -) the { -Console.WriteLine ("good afternoon."); $ } the Else if(Now <= A) the { theConsole.WriteLine ("Good Evening"); the } - Else in { theConsole.WriteLine ($"It's {now} O ' time, and you're should go to bed."); the } About } the}
C #: Number of consoles sheep small program