.Write a program that can solve these tasks: Reverses the digits of a number Calculates the average of a sequence of integers Solves a linear equation

SHARE:

Write a program that can solve these tasks:

Reverses the digits of a number Calculates the average of a sequence of integers Solves a linear equation a * x + b = 0 Create appropriate methods. Provide a simple text-based menu for the user to choose which task to solve. Validate the input data: The decimal number should be non-negative
The sequence should not be empty “a” should not be equal to 0



using System;

    class ComplexTasks
    {
        static void TaskChoice()
        {
            Console.Write("Task number: ");
            int task = int.Parse(Console.ReadLine());

            switch (task)
            {
                case 1: NumberInput();
                    TaskContinue();
                    break;
                case 2: SequenceLength();
                    TaskContinue();
                    break;
                case 3: EquationInput();
                    TaskContinue();
                    break;
                default: Console.WriteLine("Enter a number from 1 to 3!\n");
                    TaskChoice();
                    break;
            }
        }
        static void TaskContinue()
        {
            Console.WriteLine();
            Console.WriteLine("Do you want to solve something else? (Y/N)");
            char cont = char.Parse(Console.ReadLine());
            if (cont == 'Y' || cont == 'y')
            {
                TaskChoice();
            }
            else if (cont == 'N' || cont == 'n')
            {
                Console.WriteLine("Thank you for using the program!");
            }
            else
            {
                Console.WriteLine("Please, enter a correct answer!");
                TaskContinue();
            }
        }

        static void NumberInput()
        {
            bool pos = false;
            decimal number;
            do
            {
                Console.WriteLine("Enter a positive number!");
                number = decimal.Parse(Console.ReadLine());
                if (number > 0)
                {
                    pos = true;
                }
            }
            while (!pos);

            Reverse(number);
        }
        static void Reverse(decimal number)
        {
            string stringNumber = number.ToString();
            string[] reversedNumber = new string[stringNumber.Length];

            for (int i = stringNumber.Length - 1; i >= 0; i--)
            {
                reversedNumber[stringNumber.Length - i - 1] = stringNumber[i].ToString();
            }

            foreach (string digit in reversedNumber)
            {
                Console.Write(digit);
            }
            Console.WriteLine();
        }

        static void SequenceLength()
        {
            bool nonEmpty = false;
            int number;
            do
            {
                Console.WriteLine("Enter a how many real positive numbers will calculate!");
                number = int.Parse(Console.ReadLine());
                if (number > 0)
                {
                    nonEmpty = true;
                }
            }
            while (!nonEmpty);

            InputAndCalculation(number);
        }
        static void InputAndCalculation(int number)
        {
            Console.WriteLine("Enter the numbers:");
            int sum = 0;
            for (int i = 0; i < number; i++)
            {
                sum += int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Their average sum is: {0} ", (decimal)sum / number);
        }

        static void EquationInput()
        {
            bool pos = false;
            decimal a;
            do
            {
                Console.WriteLine("Enter the first number of linear equation - a>0!");
                a = decimal.Parse(Console.ReadLine());
                if (a > 0)
                {
                    pos = true;
                }
            }
            while (!pos);
            Console.WriteLine("Enter the second number of linear equation - b!");
            decimal b = decimal.Parse(Console.ReadLine());

            EquationCalculation(a, b);

        }
        static void EquationCalculation(decimal a, decimal b)
        {
            decimal x = 0;
            if (b > 0)
            {
                Console.WriteLine();
                Console.Write("Your linear equation is: {0}*X + {1} = 0\n", a, b);
                Console.WriteLine("X = {0}", x = -b / a);
            }
            else
            {
                Console.WriteLine();
                Console.Write("Your linear equation is: {0}*X - {1} = 0\n", a, Math.Abs(b));
                Console.WriteLine("X = {0}", x = b / a);
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Enter task that you want ti sovle...");
            Console.WriteLine("1. Reverses the digits of a number\n2. Calculates the average of a sequence of integers\n"
            + "3. Solves a linear equation a * x + b = 0\n");

            TaskChoice();
        }
    }

COMMENTS

Name

ADOBE ILLUSTRATOR,5,Advantages of it,14,Android,3,Android App,1,Annoucements,5,Apple,27,Apple TV 2,1,Apps,3,AutoDraw,1,Basic It,23,best rct game,4,best rct version,2,best roller coaster tycoon game,2,Black Desert Tamer,1,Blogger,1,c# tutorials,25,Cloud Computing,1,Color Schemes,1,console,1,Crowdfunding,2,Devices,1,Dock,2,elcapitan,1,Enterprise,1,Excel,1,FaceTime,1,Far Cry Primal,1,Farmville 2,5,Featured,2,Games,13,games for ios,1,Glossary,2,Google,1,google docs,1,google sheets,1,Html,3,iDevice,5,ios,1,iOS Apps,5,iOS Tweaks,1,iPhone 5,3,iPhone 5S,2,It Tricks,10,jailbreak rct,1,java,1,javascript,1,Just Cause 2,1,leeter hero,1,Mac OS X,8,macos,1,macOS,3,malwares,1,marriage in stardew valley,1,marriage stardew valley,1,Mavericks,1,Microsoft,1,Mount and Warblade,1,New Technology,6,optical character recognition,1,osx,1,php,1,Pillars of Eternity,1,PS4,1,RCT,5,RCT 2,1,RCT 3,3,rct 3 cheat,1,rct 4 hack,1,rct3,1,rct3 cheats,1,rct4,3,rct4 hack,1,RCT4 Mobile,4,rct4 redeem codes 2016,1,rct4 redeem codes 2017,1,roller coaster 3 cheats,1,rollercoaster tycoon 3,1,rollercoaster tycoon 3 money,1,rollercoaster tycoon 3 money cheat,1,Security,1,sierra,1,Sony,1,Sql,1,Stardew Valley,3,Stardew Valley Marriage,1,Store,1,Surface,1,Tamil,2,Tech,1,Ui Design,1,unflod malware,1,unlimited coins rct 4,1,Updates,1,Webdesign,5,Word,9,Wordpress,3,yosemite,1,Youtube,1,
ltr
item
Lankaitschool | Lanka itschool: .Write a program that can solve these tasks: Reverses the digits of a number Calculates the average of a sequence of integers Solves a linear equation
.Write a program that can solve these tasks: Reverses the digits of a number Calculates the average of a sequence of integers Solves a linear equation
https://4.bp.blogspot.com/-Ma7MICOItMU/Wv2ov1DBy2I/AAAAAAAAE8Y/WiJR9JENxxsnraXDVfZ6slb6aoYTXDn1wCK4BGAYYCw/s640/maxresdefault.jpg
https://4.bp.blogspot.com/-Ma7MICOItMU/Wv2ov1DBy2I/AAAAAAAAE8Y/WiJR9JENxxsnraXDVfZ6slb6aoYTXDn1wCK4BGAYYCw/s72-c/maxresdefault.jpg
Lankaitschool | Lanka itschool
http://www.lankaitschool.com/2018/05/write-program-that-can-solve-these.html
http://www.lankaitschool.com/
http://www.lankaitschool.com/
http://www.lankaitschool.com/2018/05/write-program-that-can-solve-these.html
true
7411958204546789358
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy