In: Computer Science
Write a program(C#) that prompts the user for her home planet. Based on the
user's input the program will display the following:
Input: earth
Message: earth. You are an Earthling and you have 10 fingers
Input: VENUS
Message: VENUS. You are a Venusian and you have 12 fingers
Input: Mars
Message: Mars. You are a Martian and you have 8 fingers
any other input
Message: I am sorry I don't know of that planet
You may use either the ToUpper() or ToLower() methods
You MUST USE A NESTED IF statement to solve this problem
[For full marks you need to accept all permutations of earth, venus and mars]
using System;
public class Test
{
public static void Main()
{
String str = Console.ReadLine(); // it will take input from user
// nested if
if(str.ToLower()=="earth" || str.ToLower()=="venus" || str.ToLower()=="mars")
//using ToLower(), we can accept input in any order
{
if(str=="earth") // Compare the string to find which planet user belongs too
Console.WriteLine(str+". You are an Earthling and you have 10 fingers");
else if(str=="venus")
Console.WriteLine(str+". You are a Venusian and you have 12 fingers");
else
Console.WriteLine(str+". You are a Martian and you have 8 fingers");
}
// if the user belongs to unknown planet
else
Console.WriteLine("I am sorry I don't know of that planet");
}
}
Output:-