My assignment is to write a C# program that computes weekly pay for an employee. Input the number of hours worked. The employee receives 7.50 per hour for the first 40 hours worked and 11.25 per hour for each additional hour. Create Test data before coding and running the program. This is what I have so far but I am getting lots of errors.

using System.Collections.Generic;
using System.Text;

namespace assignment11
{
    class Program
    {
        static void Main(string[] args)
        {
            //get input
            Console.Write("number of hours worked: ");
            string hours = Console.ReadLine();
            //process
            string weeklyPay;
            string numberofhours;
            string payRate;
            while(hours = 40);
             double payRate = 7.50;
             hours < 40;
            payRate = 11.25;
            weeklyPay = payRate * numberofhours;
            //show ouput
             Console.WriteLine();  //blank line
             Console.WriteLine(weeklyPay);
            //pause
             Console.WriteLine();  //blank line
             Console.Write("press enter key to continue");
             Console.ReadLine();  //pause
        }
    }

any help with what I am doing wrong would be great.

I don't want to do your homework for you. So I'll only give general tips:

1 - Read the chapter on types.
2 - Look for the definition of the equality operator.
3 - Semi-colons after while statements are usually not what a person would desire.
4 - Recheck your math

using System.Collections.Generic;
using System.Text;
using System;

namespace assignment11
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //get input
            System.Console.Write("number of hours worked: ");
            string hours = Console.ReadLine();
            //process
            int payRate;
            string weeklyPay;
            string numberofHours;
            if(numberofHours == 40)
                 payRate = 7.50;
            else
                 payRate = 11.25;
             //show ouput
             weeklyPay = payRate * numberofHours;
             System.Console.WriteLine();  //blank line
             System.Console.WriteLine(weeklyPay);
            //pause
             System.Console.WriteLine();  //blank line
             System.Console.Write("press enter key to continue");
             System.Console.ReadLine();  //pause
        }
    }
}

Ok i redid it and now I only have 5 errors but still can't get it.

Please convert the hours to integer

ie Replace string hours = Console.ReadLine(); to

int hours=Convert.ToInt32(Console.ReadLine());

change the datatye numberofhours,weeklypay to int

i hope you understood

Regards
razool

using System.Collections.Generic;
using System.Text;
using System;

namespace assignment11
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //get input
            System.Console.Write("number of hours worked: ");
            string hours = Console.ReadLine();
            //process
            int payRate;
            string weeklyPay;
            string numberofHours;
            if(numberofHours == 40)
                 payRate = 7.50;
            else
                 payRate = 11.25;
             //show ouput
             weeklyPay = payRate * numberofHours;
             System.Console.WriteLine();  //blank line
             System.Console.WriteLine(weeklyPay);
            //pause
             System.Console.WriteLine();  //blank line
             System.Console.Write("press enter key to continue");
             System.Console.ReadLine();  //pause
        }
    }
}

Ok i redid it and now I only have 5 errors but still can't get it.

Another hint for you,

Your assignment says to compute the rate at 7.5 for the first 40 hours, and 11.25 for each additional hour.

Your condition is only checking for if the hours equal exactly 40 hours then use 7.50, else use 11.25. So with your condition, if worked any hours other than exactly 40, then all of it is at 11.25.

Should be something like this.
in TotalHours = nnn
if( TotalHours <= 40 ) pay all hours at 7.50
else
pay at ( 40 * 7.50 ) + ( (TotalHours -40) * 11.25)

Hope that helps...

Ok I am still getting errors that say this
Error 1 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?) \\obt-w-olad001p\home\D03112359\My Documents\Visual Studio 2005\Projects\Assignment11\Assignment11\Assignment11.cs 21 24 Assignment11

if(numberofHours == 40)
payRate = 7.50;
else
payRate = 11.25;

I have no idea how to use a cast.

You cannot use an integer for money. It is a decimal type, and so just change your PayRate declaration to decimal or double instead of Int.

Also change your WeeklyPay variable
to decimal or double instead of string. You can always output (just about anything) as a string, but making assignments needs to be with compatible types.

BTW: normally use the Convert.To___() to cast between types.
Outputing as a string is as simple as appending the ToString() method to your variable:
decimal payrate = 40 * 7.50;
string WeeklyPay = payrate.ToString();

// Jerry

payroll system based on the two things:
*Search employees by salary range?
*Search employees by year of service?

This article has been dead for over six months. Start a new discussion instead.