Ejemplo n.º 1
0
        public static void Ex20()
        {
            Console.WriteLine("Please place your order: ");
            int    tv  = ISSConsole.ReadInt("Quantity of TV: ");
            int    dvd = ISSConsole.ReadInt("Quantity of DVD: ");
            int    mp3 = ISSConsole.ReadInt("Quantity of MP3: ");
            double discount;
            int    firstCost = tv * 900 + dvd * 500 + mp3 * 700;

            if (firstCost >= 10000)
            {
                discount = 0.15;
            }
            else if (firstCost >= 5000)
            {
                discount = 0.1;
            }
            else
            {
                discount = 0;
            }
            double totalCost = (tv * 900 + dvd * 500) * (discount + 1) + mp3 * 700;

            Console.WriteLine($"Total amount is: {totalCost}");
        }
Ejemplo n.º 2
0
        public static void Ex18()
        {
            int marks = ISSConsole.ReadInt("Please input your Marks: ");

            if (marks > 0 && marks < 100)
            {
                char grade; //Declaring
                if (marks >= 80)
                {
                    grade = 'A';
                }
                else if (marks >= 60)
                {
                    grade = 'B';
                }
                else if (marks >= 40)
                {
                    grade = 'C';
                }
                else
                {
                    grade = 'F';
                }
                Console.WriteLine($"You scored {marks} marks which is {grade} grade.");
            }
            else
            {
                Console.WriteLine("**Error**");
            }
        }
Ejemplo n.º 3
0
        public static void Ex26()
        {
            int    n      = ISSConsole.ReadInt("Please key in a number to check if it is Prime: ");
            string result = " ";

            while (n < 0)
            {
                Console.WriteLine("Please insert a positive number...");
                n = ISSConsole.ReadInt();
            }
            if (n == 1 || n == 2)
            {
                result = "Prime.";
            }
            else
            {
                for (int i = 2; i <= n / 2; i++)
                {
                    if (n % i == 0)
                    {
                        result = "Not Prime.";
                    }
                    else
                    {
                        result = "Prime.";
                    }
                }
            }
            Console.WriteLine(result);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name");
            string username = ISSConsole.ReadString();

            Console.WriteLine("Enter your gender");
            char gender = ISSConsole.ReadChar();

            Console.WriteLine("Enter your age");
            int age = ISSConsole.ReadInt();

            if (gender == 'M')
            {
                if (age >= 40)
                {
                    Console.WriteLine("Good morning Uncle {0}", username);
                }
                else
                {
                    Console.WriteLine("Good morning Mr {0}", username);
                }
            }
            else
            {
                if (age >= 40)
                {
                    Console.WriteLine("Good morning Aunty {0}", username);
                }
                else
                {
                    Console.WriteLine("Good morning Ms. {0}", username);
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a 3 digit number");
            int number = ISSConsole.ReadInt();
            int q      = number;
            int r      = 0;
            int sum    = 0;

            q   = number / 100;
            r   = number % 100;
            sum = (int)Math.Pow(q, 3);

            q   = r / 10;
            r   = r % 10;
            sum = sum + (int)Math.Pow(q, 3);

            sum = sum + (int)Math.Pow(r, 3);
            if (sum == number)
            {
                System.Console.WriteLine("The number is an armstrong number");
            }
            else
            {
                System.Console.WriteLine("The number is not an armstrong number");
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            int comp_mind = ISSMath.RNDInt(9);

            Console.WriteLine("In my mind=" + comp_mind);
            int yourguess;
            int count = 0;

            do
            {
                if (count >= 1)
                {
                    Console.WriteLine("Try again");
                }
                yourguess = ISSConsole.ReadInt("Guess the number in my mind");
                ++count;
            } while (comp_mind != yourguess);
            if (count <= 2)
            {
                Console.WriteLine("Congrats. you have made {0} attempts", count);
                Console.WriteLine("You are a wizard");
            }
            else if (count >= 3 && count <= 5)
            {
                Console.WriteLine("You are a good guess");
            }
            else
            {
                Console.WriteLine("Your are lousy");
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your score");
            int score = ISSConsole.ReadInt();

            // char grade;
            if (score >= 80 && score <= 100)
            {
                Console.WriteLine("You scored {0} marks which is A grade", score);
            }
            else if (score >= 60 && score <= 79)
            {
                Console.WriteLine("You scored {0} marks which is B grade", score);
            }
            else if (score >= 40 && score <= 59)
            {
                Console.WriteLine("You scored {0} marks which is C grade", score);
            }
            else if (score >= 0 && score <= 40)
            {
                Console.WriteLine("You scored {0} marks which is F grade", score);
            }
            else if (score < 0)
            {
                Console.WriteLine("**Error**");
            }
            else if (score > 100)
            {
                Console.WriteLine("**Error**");
            }
        }
Ejemplo n.º 8
0
        public static void Ex32()
        {
            int[] sales = new int[12];
            for (int i = 0; i < 12; i++)
            {
                sales[i] = ISSConsole.ReadInt($"Please enter sales of month {i}: ");
            }
            int min = sales[0], max = sales[0];
            int monthMin = 0, monthMax = 0;
            int sum = sales[0];

            for (int i = 1; i < 12; i++)
            {
                sum += sales[i];
                if (sales[i] < min)
                {
                    min      = sales[i];
                    monthMin = i;
                }
                if (sales[i] > max)
                {
                    max      = sales[i];
                    monthMax = i;
                }
            }
            Console.WriteLine($"The month with Maximum sales is {monthMax}");
            Console.WriteLine($"The month with Minimum sales is {monthMin}");
            Console.WriteLine($"The average monthly sales is {(double)sum/12:c}");
        }
Ejemplo n.º 9
0
        public static void Ex33()
        {
            int temp;
            int n = ISSConsole.ReadInt("Please insert length of array: ");

            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = ISSMath.RNDInt(100);
                Console.Write($"\t{array[i]}");
            }
            Console.WriteLine();
            Console.WriteLine("Simplified seclection sort method progess:");
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (array[i] < array[j])
                    {
                        temp     = array[i];
                        array[i] = array[j];
                        array[j] = temp;
                        for (int l = 0; l < n; l++)
                        {
                            Console.Write($"\t{array[l]}");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.Write("Enter a number to find whether it is perfect");
            int number = ISSConsole.ReadInt();
            int pn     = 0;

            // findOdd();
            for (int i = 1; i < number; i++)
            {
                if (number == 6)
                {
                    pn = pn + i;
                    if (pn == number)
                    {
                        System.Console.WriteLine("Perfect number");
                        break;
                    }
                }
                else
                {
                    for (int k = 1; k < 30; k++)
                    {
                        if (k % 2 != 0)
                        {
                            pn = pn + (int)Math.Pow(k, 3);
                            if (pn == number)
                            {
                                System.Console.WriteLine("Perfect number");
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            int tempa, tempb;

            Console.WriteLine("Enter 2 numbers");
            int a   = tempa = ISSConsole.ReadInt();
            int b   = tempb = ISSConsole.ReadInt();
            int hcf = 0;

            while (a != b)
            {
                if (b > a)
                {
                    b   = b - a;
                    hcf = b;
                }
                else
                {
                    a   = a - b;
                    hcf = a;
                }
            }

            Console.WriteLine("HCF={0}", hcf);

            Console.WriteLine("LCM={0}", tempa * tempb / hcf);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.Write("Enter the ordered quantity of TV");
            int q_tv = ISSConsole.ReadInt();

            Console.Write("Enter the ordered quantity of DVD");
            int q_dvd = ISSConsole.ReadInt();

            Console.Write("Enter the ordered quantity of MP3");
            int q_mp3 = ISSConsole.ReadInt();

            int price_tv  = 900;
            int price_dvd = 500;
            int price_mp3 = 700;

            double tv_orderedAmount = price_tv * q_tv;
            double dvd_orderAmount  = price_dvd * q_dvd;
            double mp3_orderAmount  = price_mp3 * q_mp3;

            double totalOrderAmount = tv_orderedAmount + dvd_orderAmount + mp3_orderAmount;

            Console.WriteLine("The total ordered amount without discount=" + totalOrderAmount);

            if (totalOrderAmount > 5000 && totalOrderAmount < 10000)
            {
                totalOrderAmount = totalOrderAmount - totalOrderAmount * 0.1;
            }
            else if (totalOrderAmount > 10000)
            {
                totalOrderAmount = totalOrderAmount - totalOrderAmount * 0.15;
            }

            Console.WriteLine("The total ordered amount with discount=" + totalOrderAmount);
        }
Ejemplo n.º 13
0
        public static void Ex22()
        {
            int RandomInteger = ISSMath.RNDInt(10);

            Console.WriteLine("Welcome to the Guess the Number Game!!");
            Console.WriteLine("Please insert a number (0~9): ");
            int count = 0;
            int guess;

            do
            {
                guess = ISSConsole.ReadInt();
                if (guess != RandomInteger)
                {
                    Console.WriteLine("Please try again!");
                    count++;
                }
                else
                {
                    if (count <= 1)
                    {
                        Console.WriteLine("You are a Wizard!");
                    }
                    else if (count <= 4)
                    {
                        Console.WriteLine("You are a good guess!");
                    }
                    else if (count <= 9)
                    {
                        Console.WriteLine("You are lousy!");
                    }
                }
            }while (guess != RandomInteger);
        }
Ejemplo n.º 14
0
        //Can we write string args[]?
        static void Main(string[] args)
        {
            Console.WriteLine("Enter an integer");
            int number = ISSConsole.ReadInt();
            //We have Math.pow
            int squareOfNumber = number * number;

            Console.WriteLine("square of the number is=" + squareOfNumber);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter an integer");
            int    number  = ISSConsole.ReadInt();
            double sqrtInt = Math.Sqrt(number);

            Console.WriteLine("The square root of {0} is {1}", number, sqrtInt);
            ISSConsole.Pause();
        }
Ejemplo n.º 16
0
        public static void Ex24()
        {
            int    n = ISSConsole.ReadInt("Please input number to find it's squart root: ");
            double g = ISSMath.RND();

            while (g * g != n)
            {
                g = (g + n / g) / 2;
            }
            Console.WriteLine($"Squart root of {n} is {g}");
        }
Ejemplo n.º 17
0
        public static void Ex21()
        {
            int x;

            do
            {
                Console.Write("Please key a number: ");
                x = ISSConsole.ReadInt();
            }while (x != 88);
            Console.WriteLine("Lucky you...");
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            //do while
            int number = 0;

            do
            {
                Console.WriteLine("Enter a number");
                number = ISSConsole.ReadInt();
            } while (number != 88);
            Console.WriteLine("Lucky you");
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a number for factorial");
            int number    = ISSConsole.ReadInt();
            int factorial = 1;

            for (int i = 1; i <= 5; i++)
            {
                factorial = factorial * i;
            }
            Console.WriteLine("The factorial is {0}", factorial);
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            int comp_mind = ISSMath.RNDInt(9);
            int yourguess;
            int count = 0;

            do
            {
                yourguess = ISSConsole.ReadInt("Guess the number in my mind");
                ++count;
            } while (comp_mind != yourguess);
            Console.WriteLine("Congrats. your have made {0} attempts", count);
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            int factorial = 1;

            Console.WriteLine("Enter a number");
            int num = ISSConsole.ReadInt();

            for (int i = num; i > 0; i--)
            {
                factorial = factorial * i;
            }

            Console.WriteLine("The factorial is {0}", factorial);
        }
Ejemplo n.º 22
0
        public static void Ex25()
        {
            int n         = ISSConsole.ReadInt("Please insert a number to find it's factorial:");
            int factorial = 1;

            if (n == 0)
            {
                factorial = 0;
            }
            else
            {
                for (int i = 1; i <= n; i++) //for (int i=n; i>0;i--)
                {
                    factorial *= i;
                }
            }
            Console.WriteLine($"Factorial of {n} is {factorial}");
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            int n = 0;

            Console.WriteLine("Enter a number to find square root");
            //Random r = new Random();
            //Console.Write("Random"+r.Next(9));
            n = ISSConsole.ReadInt();
            int g = ISSMath.RNDInt(n);
            int sqrt;

            while (g * g != n)
            {
                g = (g + (n / g)) / 2;
            }
            sqrt = g;
            Console.WriteLine("The square root of {0} is {1}", n, sqrt);
        }
Ejemplo n.º 24
0
        public static void Ex27()
        {
            int n   = ISSConsole.ReadInt("Please key in a number to check if it is Perfect number: ");
            int sum = 0;

            for (int i = 1; i < n; i++)
            {
                if (n % i == 0)
                {
                    sum += i;
                }
            }
            if (sum == n)
            {
                Console.WriteLine($"{n} is a Perfect Number.");
            }
            else
            {
                Console.WriteLine($"{n} is not a Perfect Number.");
            }
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            Console.Write("Enter a number to check prime");
            int  number = ISSConsole.ReadInt();
            bool prime  = true;

            for (int i = 2; i < number; i++)
            {
                if (number % i == 0)
                {
                    prime = false;
                    break;
                }
            }
            if (prime)
            {
                Console.WriteLine("Prime");
            }
            else
            {
                Console.WriteLine("Not Prime");
            }
        }
Ejemplo n.º 26
0
        static void usingWhile(string[] args)
        {
            Console.WriteLine("Enter a 3 digit number");
            int number = ISSConsole.ReadInt();
            int q      = number;
            int r      = 0;
            int sum    = 0;

            while (q != 0)
            {
                r   = q % 10;
                q   = q / 10;
                sum = sum + (int)Math.Pow(r, 3);
            }
            if (sum == number)
            {
                System.Console.WriteLine("The number is an armstrong number");
            }
            else
            {
                System.Console.WriteLine("The number is not an armstrong number");
            }
        }
Ejemplo n.º 27
0
        public static void Ex34()
        {
            int maxIndex = 0;
            int max;
            int n = ISSConsole.ReadInt("Please insert length of array: ");

            int[] array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = ISSMath.RNDInt(100);
                Console.Write($"\t{array[i]}");
            }
            Console.WriteLine();
            max = array[0];
            Console.WriteLine("Refined selection sort method progess:");
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (array[j] > max)
                    {
                        max      = array[j];
                        maxIndex = j;
                    }
                }
                //swap:
                array[maxIndex] = array[i];
                array[i]        = max;
                for (int l = 0; l < n; l++)
                {
                    Console.Write("\t" + array[l]);
                }
                Console.WriteLine($"\tMax= {max}");
                max      = array[i + 1];
                maxIndex = i + 1;
            }
        }
Ejemplo n.º 28
0
        public static void Ex23() //hcf & lcf
        {
            Console.WriteLine("Please input the 2 numbers to get its LCM and HCF:");
            int n1       = ISSConsole.ReadInt("Number 1 = ");
            int n2       = ISSConsole.ReadInt("Number 2 = ");
            int multiply = n1 * n2;

            while (n1 != n2)
            {
                if (n1 > n2)
                {
                    n1 -= n2;
                }
                else
                {
                    n2 -= n1;
                }
            }
            int hcf = n1;
            int lcm = multiply / hcf;

            Console.WriteLine($"LCM = {lcm}");
            Console.WriteLine($"HCF = {hcf}");
        }
Ejemplo n.º 29
0
        public static void Ex17()
        {
            Console.Write("Your name: ");
            string name = Console.ReadLine();
            int    age  = ISSConsole.ReadInt("Age: ");

            Console.Write("Gentle (F/M): ");
            char gender = ISSConsole.ReadChar();

            if (gender == 'F' || gender == 'f')
            {
                if (age < 40)
                {
                    Console.WriteLine($"Good morning Ms. {name}");
                }
                else
                {
                    Console.WriteLine($"Good morning Aunty {name}");
                }
            }
            else if (gender == 'M' || gender == 'm')
            {
                if (age < 40)
                {
                    Console.WriteLine($"Good morning Mr. {name}");
                }
                else
                {
                    Console.WriteLine($"Good morning Uncle {name}");
                }
            }
            else
            {
                Console.WriteLine("Please insert your Gender pls");
            }
        }
Ejemplo n.º 30
0
        static void Main()
        {
            Console.Write("Please choose an exercise 15-48: ");
            int choose = ISSConsole.ReadInt();

            switch (choose)
            {
            case 15:
                Exercise.Ex15();
                break;

            case 16:
                Exercise.Ex16();
                break;

            case 17:
                Exercise.Ex17();
                break;

            case 18:
                Exercise.Ex18();
                break;

            case 19:
                Exercise.Ex19();
                break;

            case 20:
                Exercise.Ex20();
                break;

            case 21:
                Exercise.Ex21();
                break;

            case 22:
                Exercise.Ex22();
                break;

            case 23:
                Exercise.Ex23();
                break;

            case 24:
                Exercise.Ex24();
                break;

            case 25:
                Exercise.Ex25();
                break;

            case 26:
                Exercise.Ex26();
                break;

            case 27:
                Exercise.Ex27();
                break;

            case 28:
                Exercise.Ex28();
                break;

            case 29:
                Exercise.Ex29();
                break;

            case 30:
                Exercise.Ex30();
                break;

            case 31:
                Exercise.Ex31();
                break;

            case 32:
                Exercise.Ex32();
                break;

            case 33:
                Exercise.Ex33();
                break;

            case 34:
                Exercise.Ex34();
                break;

            case 35:
                Exercise.Ex35();
                break;

            case 36:
                Exercise.Ex36();
                break;

            case 37:
                Exercise.Ex37();
                break;

            case 38:
                Exercise.Ex38();
                break;

            case 40:
                Exercise.Ex40();
                break;

            case 41:
                Exercise.Ex41();
                break;

            case 42:
                Exercise.Ex42();
                break;

            case 43:
                Exercise.Ex43();
                break;

            case 44:
                Exercise.Ex44();
                break;


                #region     /* Do not remove this or write codes after this  */
                ISSConsole.Pause();
                #endregion
            }
        }