Hey guys, this is the problem
Write a console-based program that prompts the user for
an hourly pay rate and hours worked. Compute gross pay
(hours times pay rate), withholding tax, and net pay (gross
pay minus withholding tax). Withholding tax is computed
as a percentage of gross pay based on the following:
Gross Pay Withholding Percentage
Up to and including 300.00= 10%
300.01 and up = 12%
Thats what i have done
double hPayRate, hWorked, grossPay, wthHoldTax, netPay;
string stringhPayRate, stringhWorked;
Console.WriteLine(" Please enter your hourly pay rate ");
stringhPayRate = Console.ReadLine();
hPayRate = Convert.ToDouble(stringhPayRate);
Console.WriteLine(" Please enter how many hours you worked ");
stringhWorked = Console.ReadLine();
hWorked = Convert.ToDouble(stringhWorked);
grossPay = hPayRate * hWorked;
if (grossPay <= 300.00)
{
wthHoldTax = grossPay * .10;
netPay = grossPay - wthHoldTax;
Console.WriteLine(" Your net pay is {0}", netPay);
}
else if (grossPay >= 300.01)
{
wthHoldTax = grossPay * .12;
netPay = grossPay - wthHoldTax;
Console.WriteLine(" Your net pay is {0}", netPay);
}
Any other cool alternative ways to solve this problem?
Loading
VulpesPosted Dec 31, 2011, 1:46 PM
VulpesPosted Dec 31, 2011, 2:38 PM
Clearly, this procedure could be generalized to deal with more than 2 variables.
Prime bPosted Dec 31, 2011, 2:20 PM
for example, here
I have to ask user two times the variables, but can I ask them two variables or three or four in one questions? and then use .ReadLine()?
Prime bPosted Dec 31, 2011, 2:02 PM