A
A
Alexa Ponamareva2021-10-30 12:10:28
C++ / C#
Alexa Ponamareva, 2021-10-30 12:10:28

Why am I getting "no overload method takes 0 arguments" error?

using System;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rnd = new Random();
            Console.WriteLine("---   Start Game   ---");
            Console.Write("\nPredict the points number (2..12) : ");

            int predict = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("User rolls the dice: " + predict + "\n");

            int summa = sum(RollTheDice(), RollTheDice());
            int score = summa - Math.Abs(summa - predict) * 2;

            Console.WriteLine("\nOn the dice fell {0} points", summa);
            Console.WriteLine("\nResult {0}-abs({0}-{1})*2: {2} points", summa, predict, score);

            if (score > 0)
            {
                Console.WriteLine("\nUser wins!.");
            }
            else
            {
                Console.WriteLine("\nUser lose!");
            }
        }
        public int RollTheDice(int number)
        {
            Random rnd = new Random();
            number = rnd.Next(1, 7);
            Printdice(number);
            return number;
        }
        public int sum(int n1, int n2)
        {
            return n1 + n2;
        }
        static void Printdice(int number)
        {
            switch (number)
            {
                case 1:
                    Console.WriteLine("---------");
                    Console.WriteLine("|       |");
                    Console.WriteLine("|   #   |");
                    Console.WriteLine("|       |");
                    Console.WriteLine("---------");
                    break;
                case 2:
                    Console.WriteLine("---------");
                    Console.WriteLine("| #     |");
                    Console.WriteLine("|       |");
                    Console.WriteLine("|     # |");
                    Console.WriteLine("---------");
                    break;
                case 3:
                    Console.WriteLine("---------");
                    Console.WriteLine("| #     |");
                    Console.WriteLine("|   #   |");
                    Console.WriteLine("|     # |");
                    Console.WriteLine("---------");
                    break;
                case 4:
                    Console.WriteLine("---------");
                    Console.WriteLine("| #   # |");
                    Console.WriteLine("|       |");
                    Console.WriteLine("| #   # |");
                    Console.WriteLine("---------");
                    break;
                case 5:
                    Console.WriteLine("---------");
                    Console.WriteLine("| #   # |");
                    Console.WriteLine("|   #   |");
                    Console.WriteLine("| #   # |");
                    Console.WriteLine("---------");
                    break;
                case 6:
                    Console.WriteLine("---------");
                    Console.WriteLine("| # # # |");
                    Console.WriteLine("|       |");
                    Console.WriteLine("| # # # |");
                    Console.WriteLine("---------");
                    break;
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Griboks, 2021-10-30
@didiwka

int summa = sum(RollTheDice(), RollTheDice());
...
public int RollTheDice(int number)

As you can see, you forgot to specify the argument in parentheses.

F
freeExec, 2021-10-30
@freeExec

Because you forgot to write the method you're calling.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question