Answer to Question #264214 in C# for Tori

Question #264214

Create a program that uses two private methods. The first method should have two responses depending on if there is an input or not. It is to request a name and output a greeting or if no name is input, it outputs "Be that way, then."

The second method is to calculate the height of the person, converting their height in inches to cm.

the program is to end with telling the user "______Name____, you are ___number____ cm tall"


1
Expert's answer
2021-11-11T07:30:37-0500

using System;


namespace Q264214

{

  //Create a program that uses two private methods. The first method should have two responses depending on if there is an input or not. It is to request a name and output a greeting or if no name is input, it outputs "Be that way, then."


  //The second method is to calculate the height of the person, converting their height in inches to cm.


  //the program is to end with telling the user "______Name____, you are ___number____ cm tall"

  class Program

  {

    static void Main(string[] args)

    {

      Console.WriteLine("Enter a name");

      var name = Console.ReadLine();

      if (OutputGreeting(name))

      {

        Console.WriteLine("Enter your height in inches");

        var inches = Convert.ToInt32(Console.ReadLine());

        var heightInCm = ConvertInToCm(inches);

        Console.WriteLine($"{name}, you are {heightInCm} cm tall");

      }

    }


    /// <summary>

    /// Takes a name and outputs a greeting and returns true or a standard message if no greeting is provided and returns false

    /// </summary>

    /// <param name="name"></param>

    /// <returns>true/false</returns>

    private static bool OutputGreeting(string name)

    {

      if (!string.IsNullOrEmpty(name))

      {

        Console.WriteLine($"Hi {name}");

        return true;

      }

      else

      {

        Console.WriteLine("Be that way, then.");

        return false;

      }

    }


    /// <summary>

    /// Converts inches to centimeters

    /// </summary>

    /// <param name="inches"></param>

    /// <returns>centimeters as a double</returns>

    private static double ConvertInToCm(int inches) 

    {

      return inches * 2.54;

    }

  }

}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS