Question

In: Computer Science

Write a program(C#) that prompts the user for her home planet. Based on the user's input...

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]

Solutions

Expert Solution

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:-


Related Solutions

2) Write a program(C#) that prompts the user for her home planet. Based on the user's...
2) 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...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT