In: Computer Science
C#
Write a program in C# that prompts the user for a name, Social Security number, hourly pay rate, and number of hours worked. In an attractive format, dis- play all the input data as well as the following: » Gross pay, defined as hourly pay rate times hours worked » Federal withholding tax, defined as 15% of the gross pay » State withholding tax, defined as 5% of the gross pay » Net pay, defined as gross pay minus taxes
This questions wants us to take input from the user and then in return perform some calculations as mentioned above and return the calculated: Gross Pay, Federal Wtithholding Tax, State Withholding Tax and Net Pay.
I have tried to output these results in a tabular format, Kindly adjust spacing accordingly.
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
// Type your username and press enter
Console.WriteLine("Enter name:");
// Create a string variable and get user input from the keyboard and store it in the variable
string name = Console.ReadLine();
// Type your Social Security Number and press enter
Console.WriteLine("Enter Social Security Number:");
// Create a string variable and get user input from the keyboard and store it in the variable
string securityNumber = Console.ReadLine();
// Type your Hourly Pay Rate and press enter
Console.WriteLine("Enter Hourly Pay Rate:");
// Create a string variable and get user input from the keyboard and store it in the variable
string payRate = Convert.ToInt32(Console.ReadLine());
// Type your Number of Hours Woked and press enter
Console.WriteLine("Enter Number of Hours Woked:");
// Create a string variable and get user input from the keyboard and store it in the variable
string hours = Convert.ToInt32(Console.ReadLine());
// Calculations
int grossPay = payRate * hours;
double federalTax = grossPay * 0.15;
double stateTax = grossPay * 0.05;
double netPay = grossPay - federalTax - stateTax;
// Now we will display the calculations done on the input
Console.WriteLine("Your Gross Pay, Federal Withholding Tax, State Withholding Tax and Net Pay are as follows: ");
Console.Write("\n\n");
Console.Write("_________________________________________________________________________");
Console.Write("| Gross Pay | Federal Withholding Tax | State Withholding Tax | Net Pay |");
Console.Write("_________________________________________________________________________");
Console.Write("| ", grossPay, " | ", federalTax, " | ", stateTax, " | ", netPay, " |");
Console.Write("_________________________________________________________________________");
}
}
}