In: Computer Science
Create an enumeration named Planet that holds the names for the eight planets in our solar system, starting with MERCURY equal to 1 and ending with NEPTUNE.
Write a program named Planets that prompts the user for a numeric position, and display the name of the planet that is in the requested position.
For example, if 3 is input, the output would be: EARTH is 3 planet(s) from the sun
Answer in C#
(Posting incomplete and probably wrong code that i have so far for this attempt. any help is appreciated.)
using System;
using static System.Console;
class Planets
{
{
enum Planets { Mercury, Venus, Earth, Mars, Jupiter, Saturn,
Neptune, Uranus };
static void Main(string[] args)
{
WriteLine("Enter position for the planet: \n");
string input = ReadLine();
int number; Int32.TryParse(input, out number);
Planets planet = (Planets)1;
WriteLine("The planet is " + planet);
}
}
}
using System;
class Planet
{
enum Planets { Mercury = 1, Venus, Earth,
Mars, Jupiter, Saturn, Neptune, Uranus }; // here we set
index
static void Main(string[] args)
{
Console.Write("Enter
position for the planet: ");
string input =
Console.ReadLine();
int num =
Convert.ToInt32(input); // convert to int and save in num
Console.WriteLine(Enum.GetName(typeof(Planets),
num)+" is " + input + " planet(s) from the sun" );
Console.Read(); //
TO STOP CONSOLE
}
}
/* OUTPUT */