I have NO idea why C# is so difficult for me when C++ is a breeze. I want to preface this post with this:
Yes, this is for a class still. But I'm only coming to people more knowledgable than I because... I just don't get it. I've read my chapter on this 5 or 6 times, looked at the examples, did the practice excercises, etc. It just goes over my head.
This is the basic code I wrote out to do a payroll program using diffent methods.
using SC = System.Console;
using System;
public class Lab15
{
//Main method begins
public static void Main()
{
//Variables
string hoursWorkedStr, payRateStr, empName;
double hoursWorked, payRate, grossPay, stateTax, federalTax, ficaTax, netPay;
SC.WriteLine("Lab 15");
//Priming read
SC.WriteLine("\nPlease input employee name (or Quit to end program): ");
empName = Console.ReadLine();
//Loop
while(empName != "Quit" && empName != "quit")
{
//Inputs
SC.WriteLine("\nPlease input hours worked:\t");
hoursWorkedStr = Console.ReadLine();
hoursWorked = Convert.ToDouble(hoursWorkedStr);
SC.WriteLine("\nPlease input rate of pay:");
payRateStr = Console.ReadLine();
payRate = Convert.ToDouble(payRateStr);
//Calculations
grossPay = CalcGrossPay(hoursWorked, payRate);
stateTax = CalcStateTax(grossPay);
federalTax = CalcFederalTax(grossPay);
ficaTax = CalcFICATax(grossPay);
netPay = CalcNetPay(grossPay);
//Output
SC.WriteLine("\nGross pay is: {0,8}", grossPay.ToString("C2"));
SC.WriteLine("State tax is: {0,8}", stateTax.ToString("C2"));
SC.WriteLine("Federal tax is: {0,8}", federalTax.ToString("C2"));
SC.WriteLine("FICA tax is: {0,8}", ficaTax.ToString("C2"));
SC.WriteLine("Net pay is: {0,8}", netPay.ToString("C2"));
//Continue priming read logic
SC.WriteLine("\nPlease input employee name (or Quit to end program): ");
empName = Console.ReadLine();
//Main method ends
}
//End statement
SC.WriteLine("\nEnd of Lab 15\n");
}
//Gross pay method
public static double CalcGrossPay(double hoursWorked, double payRate)
{
double grossPay = hoursWorked * payRate;
return grossPay;
}
//State tax method
public static double CalcStateTax(double grossPay)
{
double stateTax = grossPay * .04;
return stateTax;
}
//Federal tax method
public static double CalcFederalTax(double grossPay)
{
double federalTax = grossPay * .23;
return federalTax;
}
//FICA tax method
public static double CalcFICATax(double grossPay)
{
double ficaTax = grossPay * .14;
return ficaTax;
}
//Net pay method
public static double CalcNetPay(double grossPay)
{
double taxes = CalcStateTax(grossPay)+CalcFederalTax(grossPay)+CalcFICATax(grossPay);
double netPay = grossPay - taxes;
return netPay;
}
}
My specs say "Calculation of gross pay should be done in a method that uses two value parameters and returns the gross pay. Calculation of State Tax should be done in a void method that uses an output parameter for State Tax and a value parameter for the gross pay. Other methods should be void and use reference parameters. Again, do not use any global variables."
I'm not asking for anyone to DO my work. I'm just asking for someone to explain to me HOW to do my work. I'm always saying me knowing how is more important than my grade, but I'm drowning.