N
N
NikitaSova2020-06-06 19:41:21
C++ / C#
NikitaSova, 2020-06-06 19:41:21

How to solve problem CS0161 in C#?

Hey!

I am new to C# and have recently started learning about functions. I need to make a program that asks for numbers, a sign and performs an action (the calculator is shorter). But I ran into a problem, here's what it sounds like:
Severity Code Description Project File String Suppression Status
Error CS0161 '"Program.Nikita(int, int, char)": not all code paths return a value.
here is the program code:

public static int Nikita(int a, int b, char d)
        {
            switch (d)

            {
                case '+':
                  return a + b;
                case '-':
                  return a - b;
                case '*':
                  return a * b;
                case '/':
                  return a / b;
                default:
                   Console.WriteLine("Ошибка");
                   break;


            }
            //return a - b;
        }
        static void Main(string[] args)
        {   
            {
                Console.Write("вевдите первое число: ");
                int am = (int)Convert.ToInt64(Console.ReadLine());
                Console.Write("введите знак: ");
                char dm = Convert.ToChar(Console.ReadLine());
                Console.Write("введите второе число: ");
                int bm = (int)Convert.ToInt64(Console.ReadLine());
                int resault = Nikita(am, bm, dm);
                Console.WriteLine(am);
                Console.WriteLine(bm);
                Console.WriteLine(dm);
                Console.WriteLine(resault);

            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2020-06-06
@NikitaSova

Well, they even write to you in Russian (by the way, switch to English. And wrap the code in a code tag) ...
What should the Nikita function return if I pass 'q' as the third parameter, for example?
A function with a return parameter must ALWAYS return a value. Or throw an exception.

F
freeExec, 2020-06-06
@freeExec

Uncommentreturn a - b;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question