Премини към съдържанието
Форумът в приложение

По-лесно сърфиране. Научи повече.

Kaldata.com - Форуми

Приложение на форума на цял екран с push известия, значки и други.

За да инсталирате това приложение на iOS и iPadOS
  1. Докоснете Иконата за споделяне в Safari
  2. Превъртете менюто и докоснете Добавяне към началния екран.
  3. Докоснете Добавяне в горния десен ъгъл.
За да инсталирате това приложение на Android
  1. Докоснете менюто с 3 точки (⋮) в горния десен ъгъл на браузъра.
  2. Докоснете Добавяне към началния екран или Инсталиране на приложение.
  3. Потвърдете, като докоснете Инсталиране.

Добре дошли!

Добре дошли в нашите форуми, пълни с полезна информация. Имате проблем с компютъра или телефона си? Публикувайте нова тема и ще намерите решение на всичките си проблеми. Общувайте свободно и открийте безброй нови приятели.

Моля, регистрирайте се за да публикувате тема и да получите пълен достъп до всички функции.

 

C# грешки, цикли

Featured Replies

Здравейте! 

Реших тези дни да се занимавам с едно проектче, което представлява калкулаторче, което ще си развивам, но ми трябва малко помощ с две неща!

Първо - прочетох за try catch и как работят, но не мога да разбера как да ги използвам в моят код. Намирам доста места, на които може да стане някаква грешка, и искам програмата директно да напише какъв е проблемът. 

Второ - Да речем, че искам да попитам потребителя с какви данни иска да работи (double, int, long, ulong и т.н), и той отговори, че иска да прави някакви сметки с числа от тип double, когато въведе число, програмата да не изгърми? Ще съм много радостен ако сте ме разбрали.

Tрето - Когато попитам потребителя, с КОЛКО на брой числа иска да извърши сметката, т.е 2,3,4,5,6, и той отговори 4, как да направя така, че потребителя да има възможност да ги въведе (по 1 на ред) и програмата да извърши нужното пресмятане?

Все още съм нов в програмирането, това почна да ми става хоби, имам още мноооого да се уча, но ще се радвам на малко помощ! (Готов съм да бъда яростно критикуван! :D)

Това е целият код.

Цитат

using System;

namespace Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            string operationType;
            int operationTimes; 
            Console.WriteLine("What operation do you want? For operation list type /help");
            Console.Write("Operation: ");
            operationType = Console.ReadLine();
            while (operationType != "add" && operationType != "subtract" && operationType != "multiply" && operationType != "divide" && operationType != "/help")
            {
                Console.WriteLine("Sorry, you must enter valid operation. For operation list type /help!");
                Console.Write("Operation: ");
                operationType = Console.ReadLine();
            }
            long firstNumber;
            long secondNumber;

            if (operationType == "add")
            {
                Console.WriteLine("How many operations do you want?");
                Console.Write("Operations: ");
                operationTimes = int.Parse(Console.ReadLine());
        
                int operationCount = 0;

                while (operationCount < operationTimes)
                {
                    Console.WriteLine("Please enter 2 numbers below!");
                    Console.Write("First number: ");
                    firstNumber = long.Parse(Console.ReadLine());
                    Console.Write("Second number: ");
                    secondNumber = long.Parse(Console.ReadLine());
                    operationCount++;
                    Console.WriteLine($"The answer is: {firstNumber + secondNumber}");
                }
            }
            if (operationType == "subtract")
            {
                Console.WriteLine("How many operations do you want?");
                Console.Write("Operations: ");
                operationTimes = int.Parse(Console.ReadLine());
                while (operationTimes != int.MaxValue)
                {
                    Console.WriteLine("Please enter valid number!");
                    Console.Write("Operations: ");
                    operationTimes = int.Parse(Console.ReadLine());
                }
                int operationCount = 0;

                while (operationCount < operationTimes)
                {
                    Console.WriteLine("Please enter 2 numbers below!");
                    Console.Write("First number: ");
                    firstNumber = long.Parse(Console.ReadLine());
                    Console.Write("Second number: ");
                    secondNumber = long.Parse(Console.ReadLine());
                    operationCount++;
                    Console.WriteLine($"The answer is: {firstNumber - secondNumber}");
                }

            }
            if (operationType == "divide")
            {
                Console.WriteLine("How many operations do you want?");
                Console.Write("Operations: ");
                operationTimes = int.Parse(Console.ReadLine());
                int operationCount = 0;

                while (operationCount < operationTimes)
                {
                    Console.WriteLine("Please enter 2 numbers below!");
                    Console.Write("First number: ");
                    firstNumber = long.Parse(Console.ReadLine());
                    Console.Write("Second number: ");
                    secondNumber = long.Parse(Console.ReadLine());
                    operationCount++;
                    Console.WriteLine($"The answer is: {firstNumber / secondNumber}");
                }

            }
            if (operationType == "multiply")
            {
                Console.WriteLine("How many operations do you want?");
                Console.Write("Operations: ");
                operationTimes = int.Parse(Console.ReadLine());
                int operationCount = 0;

                while (operationCount < operationTimes)
                {
                    Console.WriteLine("Please enter 2 numbers below!");
                    Console.Write("First number: ");
                    firstNumber = long.Parse(Console.ReadLine());
                    Console.Write("Second number: ");
                    secondNumber = long.Parse(Console.ReadLine());
                    operationCount++;
                    Console.WriteLine($"The answer is: {firstNumber * secondNumber}");
                }
            }
              if (operationType == "/help")
            {
                Console.WriteLine("Type 'add' to add numbers.");
                Console.WriteLine("Type 'subtract' to subtract numbers.");
                Console.WriteLine("Type 'multiply' to multiply the numbers.");
                Console.WriteLine("Type 'divide' to divide the numbers.");
                Console.WriteLine("So what operation do you want?");
                Console.Write("Operation: ");
                operationType = Console.ReadLine();

                if (operationType == "add")
                {
                    Console.WriteLine("How many operations do you want?");
                    Console.Write("Operations: ");
                    operationTimes = int.Parse(Console.ReadLine());
                    int operationCount = 0;

                    while (operationCount < operationTimes)
                    {
                        Console.WriteLine("Please enter 2 numbers!");
                        Console.Write("First number: ");
                        firstNumber = long.Parse(Console.ReadLine());
                        Console.Write("Second number: ");
                        secondNumber = long.Parse(Console.ReadLine());
                        Console.WriteLine($"The answer is: {firstNumber + secondNumber}");
                        operationCount++;
                    }
                    
                }
                if (operationType == "subtract")
                {
                    Console.WriteLine("How many operations do you want?");
                    Console.Write("Operations: ");
                    operationTimes = int.Parse(Console.ReadLine());
                    int operationCount = 0;

                    while (operationCount < operationTimes)
                    {
                        Console.WriteLine("Please enter 2 numbers below!");
                        Console.Write("First number: ");
                        firstNumber = long.Parse(Console.ReadLine());
                        Console.Write("Second number: ");
                        secondNumber = long.Parse(Console.ReadLine());
                        operationCount++;
                        Console.WriteLine($"The answer is: {firstNumber - secondNumber}");
                    }

                }
                if (operationType == "divide")
                {
                    Console.WriteLine("How many operations do you want?");
                    Console.Write("Operations: ");
                    operationTimes = int.Parse(Console.ReadLine());
                    int operationCount = 0;

                    while (operationCount < operationTimes)
                    {
                        Console.WriteLine("Please enter 2 numbers below!");
                        Console.Write("First number: ");
                        firstNumber = long.Parse(Console.ReadLine());
                        Console.Write("Second number: ");
                        secondNumber = long.Parse(Console.ReadLine());
                        operationCount++; 
                        Console.WriteLine($"The answer is: {firstNumber / secondNumber}");
                    }

                }
                if (operationType == "multiply")
                {
                    Console.WriteLine("How many operations do you want?");
                    Console.Write("Operations: ");
                    operationTimes = int.Parse(Console.ReadLine());
                    int operationCount = 0;

                    while (operationCount < operationTimes)
                    {
                        Console.WriteLine("Please enter 2 numbers below!");
                        Console.Write("First number: ");
                        firstNumber = long.Parse(Console.ReadLine());
                        Console.Write("Second number: ");
                        secondNumber = long.Parse(Console.ReadLine());
                        operationCount++;
                        Console.WriteLine($"The answer is: {firstNumber * secondNumber}");
                    }
                }
            }

        }
    }
}

 

 

Архивирана тема

Темата е твърде стара и е архивирана. Не можете да добавяте нови отговори в нея, но винаги можете да публикувате нова тема, в която да продължи дискусията. Регистрирайте се или влезте във вашия профил за да публикувате нова тема.

Разглеждащи това в момента 0

  • Няма регистрирани потребители разглеждащи тази страница.

Дарение

  • Подкрепи съществуването на форума - направи дарение
    25%
    Дарени 252.69 EUR от нужните 1,000.00 EUR

Бюлетин

Получавайте известие, когато има важна промяна или новина свързана с форума.

Профил

Навигация

Търсене

Търсене

Конфигуриране на push известия в браузъра

Chrome (Android)
  1. Докоснете иконата на катинар до адресната лента.
  2. Докоснете Разрешения → Известия.
  3. Променете предпочитанията си.
Chrome (Desktop)
  1. Кликнете върху иконата на катинар в адресната лента.
  2. Изберете Настройки на сайта.
  3. Намерете Известия и коригирайте предпочитанията си.