Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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% More than300.00 12%









I got = error how can i solve that?

ERROR : else (grossIncome > = 300.000);

What I have tried:

C#
using System;

namespace Question_6
{
    class Program
    {
        static void Main(string[] args)
        {
            double workhours, payRateHours, grossIncome, netIncome, wthTax;

            String SPayRate, SWorkhours;

            Console.WriteLine("PLEASE ENTER THE HOURLY PAY RATE");
            SPayRate = Console.ReadLine();
            payRateHours = Convert.ToDouble(SPayRate);

            Console.WriteLine("PLEASE ENTER HOW MANY HOURS YOU ARE WORKING");
            SWorkhours = Console.ReadLine();
            workhours = Convert.ToDouble(SWorkhours);

            grossIncome = payRateHours * workhours;

            if (grossIncome < 300.000)
            {
                wthTax = grossIncome * .10;
                netIncome = grossIncome - wthTax;
                Console.WriteLine("Your net pay {0}", netIncome);

            }
            else (grossIncome > = 300.000);
            { 
                wthTax = grossIncome * .12;
                netIncome = grossIncome - wthTax;
                Console.WriteLine("Your net pay{0}", netIncome);

                Console.ReadKey();
            }
        }
    }
}
Posted
Updated 4-Feb-22 7:14am
v2
Comments
thatraja 4-Feb-22 12:39pm    
Include complete error message in your question
0x01AA 4-Feb-22 12:41pm    
Looks like simply one space to much here else (grossIncome > = 300.000);.
Try this:
else (grossIncome >= 300.000);

Remove the following

(grossIncome > = 300.000);


It serves no purpose because you test to see if grossIncome is less than 300.000 which means you do not need to test if the greater than or equal 300.00 for the else part.
 
Share this answer
 
v3
Comments
0x01AA 5-Feb-22 3:11am    
The only correct answer here. A 5.
You are checking the grossIncome greater than and equality, In simple else statement it will through an error because onle else doesn't contain condition you need to use else-if, change your else line with the following:
else if(grossIncome >= 300.000)
{
    // Your Code
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900