bài tập đầu tiên

PHOTO EMBED

Sat Oct 02 2021 09:16:05 GMT+0000 (UTC)

Saved by @_Ryan_ #c#

using System;

namespace ConsoleApp1
{
    class Program
    {
       
        
        
             
        static void Main(string[] args)
        {

            //  Information();
            //  CountTime();
            // CheckMonth();
            // sell_sticket();
            Count_odd_Number();


        }

        static void Information()
        {

            Console.Write("Enter total: ");
            int total = int.Parse(Console.ReadLine());
            string[] Name = new string[total];
            int[] Age = new int[total];
            float[] Grade = new float[total];

            for (int i = 0; i < total; i++)
            {
                Console.Write("Enter Name {0}: ", i + 1);
                Name[i] = Console.ReadLine();
                Console.Write("Enter Age {0}: ", i + 1);
                Age[i] = int.Parse(Console.ReadLine());
                Console.Write("Enter Grade {0}: ", i + 1);
                Grade[i] = float.Parse(Console.ReadLine());
            }

            for (int i = 0; i < total; i++)
            {
                Console.WriteLine($"Name {i + 1}: {Name[i]}, Age {i + 1}: {Age[i]}, Grade {i + 1}: {Grade[i]}");
            }


            for (int i = 0; i < total; i++)
            {
                if (Grade[i] < 3.0)
                {
                    Console.WriteLine($"Name: {Name[i]} > false");
                }
                else
                {
                    Console.WriteLine($"Name: {Name[i]} > passed");
                }
            }
        }


        static void CountTime()
        {

            int hour, minute, add;
            do
            {
                Console.Write("Enter Hour: ");
                hour = int.Parse(Console.ReadLine());
                if(hour > 23 || hour < 0)
                {
                    Console.WriteLine("Enter hour again ! 0h-23h");
                }
               
            } while (hour > 23 || hour < 0);
            do
            {
                  Console.Write("Enter Minute: ");
                  minute = int.Parse(Console.ReadLine());
                if(minute < 1)
                {
                    Console.Write("Enter minute again! 1-30p");
                }
            } while (minute < 1);
           
            Console.Write("add minute: ");
            add = int.Parse(Console.ReadLine());
            minute = minute + add;
            
          
            if(minute > 59)
            {
                hour = hour + 1;
                if(hour > 23)
                {
                    hour = 00;
                }
                minute = minute - 60;
            }
            
            Console.Write($"Next time is: {hour}:{minute}");
               
        }

        static void CheckMonth()
        {
            int month;
            do
            {
                Console.Write("Enter Moth: ");
                month = int.Parse(Console.ReadLine());
                if (month <= 0 || month > 12)
                {
                    Console.WriteLine("ERROR!");
                }
            } while (month <= 0 || month > 12);
           
            switch(month)
            {
                case 1: Console.WriteLine("January"); break;
                case 2: Console.WriteLine("February"); break;
                case 3: Console.WriteLine("March"); break;
                case 4: Console.WriteLine("April"); break;
                case 5: Console.WriteLine("May"); break;
                case 6: Console.WriteLine("June"); break;
                case 7: Console.WriteLine("July"); break;
                case 8: Console.WriteLine("August"); break;
                case 9: Console.WriteLine("September"); break;
                case 10: Console.WriteLine("October"); break;
                case 11: Console.WriteLine("November"); break;
                case 12: Console.WriteLine("December"); break;
            }
        }

        static void sell_sticket()
        {
            string day;
            int age, price = 0;

            Console.Write("Enter Day: ");
            day = Console.ReadLine().ToLower();
            do
            {
                Console.Write("Enter Age: ");
                age = int.Parse(Console.ReadLine());
                if(age <= 0 || age >= 122)
                {
                    Console.Write("ERROR! enter again");
                }
            } while (age <= 0 || age >= 122);
            
            switch (day)
            {
                case "weekday": 
                 
                    if(0 <= age && age <= 18 || 64 < age && age <= 122)
                    {
                        price = 12;
                    }
                    else
                    {
                        price = 18;
                    }    
                    break;
                case "weekend":
                    
                    if (0 <= age && age <= 18 || 64 < age && age <= 122)
                    {
                        price = 15;
                    }
                    else
                    {
                        price = 18;
                    }
                    break;
                case "holiday":
                        
                    if (0 <= age && age <= 18)
                    {
                        price = 5;
                    }
                    else if (64 < age && age <= 122)
                    {
                        price = 10;
                    }
                    else
                    {
                        price = 12;
                    }
                    break;
            }
           
           Console.Write($"price: {price}");
        }

        static void Count_odd_Number()
        {
            int value, temp, sum = 0;
            
            do
            {
                Console.Write("Enter value: ");
                value = int.Parse(Console.ReadLine());
                if(value > 100 || value < 1)
                {
                    Console.Write("Enter value from 1 to 100");
                }
            } while (value > 100 || value < 1);
            
          for(int i = 1, j = 1; j <= value;i++)
            {
                temp = i % 2;
                if(temp != 0)
                {
                    sum = sum + i;
                    j++;
                }
            }                       
            Console.Write($"SUM odd number = {sum}");
        }
        }
    }
content_copyCOPY