nico_
nico_

Reputation: 1

Hi, I am unable to make this code work as it is saying "not all code paths return a value." I am not sure what is not working here

using System;

namespace code1
{
    class Program
    {
        static object main()
        {
            Console.WriteLine("What's your name?");
            string input = Console.ReadLine();
            Console.WriteLine($"Hello {input}!");
            /* This part will tell the user their age in a string */
            Console.WriteLine("How old are you?");
            double age = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine($"You are {age} years old");
            Console.WriteLine("Next Part....");
            Console.WriteLine("Next.");


        }
    }
    
}

Upvotes: 0

Views: 28

Answers (2)

mademyday
mademyday

Reputation: 83

You have a wrong return type for the function main. It should return nothing = void.

using System;

namespace code1
{
    class Program
    {
        static void main()
        {
            Console.WriteLine("What's your name?");
            string input = Console.ReadLine();
            Console.WriteLine($"Hello {input}!");
            /* This part will tell the user their age in a string */
            Console.WriteLine("How old are you?");
            double age = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine($"You are {age} years old");
            Console.WriteLine("Next Part....");
            Console.WriteLine("Next.");


        }
    }
    
}

Edit 2: You should also be consistent with datatypes. You are defining age as double but converting the user input to Int32. Either use Convert.ToDouble() or change variable declaration to int (or var to use inference).

Upvotes: 1

Mark
Mark

Reputation: 84

Type return of method is Object, but you don't return anything. static object main()

Edit: static void main()

Upvotes: 0

Related Questions