SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    AZ
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple C# question

    I'm trying to add .5 to the wage rate of any hour worked over 40. The error i get is Error Operator '*' cannot be applied to operands of type 'bool' and 'double' This is for my programming class.

    private static double CalcPay(double Hours, double WageRate, double SalesAmount)
    {
    double GrPay;
    GrPay = Hours * WageRate;
    if (SalesAmount >= 0)
    { GrPay = (.02 * SalesAmount) + SalesAmount + GrPay; }
    else if (Hours > 40)
    { GrPay = (Hours > 40) * (.5 * WageRate); };
    return GrPay;

    Thanks a ton for your help.

    Ps if you need the full code here it is ---

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

    /* Kevin N

    * CIS 220

    * Professor Morgan

    * Sep. 21, 2009

    */


    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    int NumberOfDependants;
    double Hours, WageRate, SalesAmount, GrossPay, TaxDeducted, NetPay;
    string SalespersonFlag;

    Console.WriteLine("Welcome to the Pay Estimator");

    Console.Write("\nEnter your # of hours worked this week: ");
    Hours = double.Parse(Console.ReadLine());
    Console.Write("Enter your hourly wage rate <e.g. 7.25>: ");
    WageRate = double.Parse(Console.ReadLine());
    Console.Write("Enter your # of dependants: ");
    NumberOfDependants = int.Parse(Console.ReadLine());
    Console.Write("\nAre You a SalesPerson?: ");
    SalespersonFlag = Console.ReadLine();
    if (SalespersonFlag == "Y" || SalespersonFlag == "y" || SalespersonFlag == "yes")
    {
    Console.Write("\nEnter the $ value of your sales this week: ");
    SalesAmount = double.Parse(Console.ReadLine());
    }
    else
    { SalesAmount = -999; };
    GrossPay = CalcPay(Hours, WageRate, NumberOfDependants);
    TaxDeducted = CalcTaxes(GrossPay, NumberOfDependants);
    NetPay = GrossPay - TaxDeducted;
    Console.WriteLine("\n\tYour GrossPay is: " + GrossPay.ToString("C"));
    Console.WriteLine("\tYour taxes deducted are: " + TaxDeducted.ToString("C"));
    Console.WriteLine("\tYour take home pay will be: " + NetPay.ToString("C"));

    Console.ReadLine();

    }
    private static double CalcPay(double Hours, double WageRate, double SalesAmount)
    {
    double GrPay;
    GrPay = Hours * WageRate;
    if (SalesAmount >= 0)
    { GrPay = (.02 * SalesAmount) + SalesAmount + GrPay; }
    else if (Hours > 40)
    { GrPay = (Hours > 40) * (.5 * WageRate); };
    return GrPay;

    }
    private static double CalcTaxes(double GrPay, int NoOfDepends)
    {
    double TaxesPaid;
    int PayCutoff;
    PayCutoff=100 + 100 * NoOfDepends;
    if (GrPay <= PayCutoff)
    { TaxesPaid = .1 * GrPay; }
    else
    { TaxesPaid = .1 * PayCutoff + .2 * (GrPay - PayCutoff); }
    return TaxesPaid;



    }
    }
    }

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    (Hours > 40) is a condition that evaluates to a boolean. You want (Hours - 40), a number, times the overtime rate.

    That rate is (WageRate + 0.5), not (.5 * WageRate), which would be half pay.

    Just watch your arithmetic and you'll get it right.

  3. #3
    SitePoint Member
    Join Date
    Jul 2004
    Location
    AZ
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help got it working.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •