• 0

C# Employee Gross Pay using While Loop


Question

Hi, This is a homework assignment I have been working on and have gotten stuck. This is what the assignment is:

 

Develop a C# console application that will determine the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40 hours. You are given a list of the three employees of the company, the number of hours each employee worked last week, and the hourly rate of each employee. Your application should input this information for each employee and should determine and display the employee

9 answers to this question

Recommended Posts

  • 0

As others already said, use Convert.ToDouble to solve the error while compiling.

 

I noticed a problem with your calculation when extra hours are involved:

  • First you need to calculate 40 hours multiplied by the regular hourly rate. These are the first 40 hours which should always be multiplied by the regular hourly rate.
  • Then add the result of the extra hours multiplied by the extra hourly rate.

Here's an example:

total = (40 * rate) + ((hours - 40) * (1.5 * rate));

This calculates the right gross pay you are looking for.

 

Test your current calculation implementation with inputs of 50 hours and $10 hourly rate. The correct result should be:

total = (40 * 10) + ((10) * (15));
total = $550
  • 0

You have a few issues in your code.  Look at your variable types too.

Convert.ToInt32

You're using this method to parse the numbers into doubles but you're using the method ToInt32 so you will lose anything anything the decimal point.    You want Convert.ToDouble().

total = (double) hours * (double) rate;

Not a bug but you don't need the (double) casts here.  You're doing double = double * double which is okay - no data loss.

  • 0

Keep it all doubles or floats internally. If you really need to cast it to integer do it as a one liner in the print statement.

That makes it easier to read and reduces rounding errors and excessive cpu cycles.

This should be a simple program. Look at your pseudo code and see if you can make it simpler?

  • 0
  On 06/04/2015 at 01:17, thehappygoldenlady said:

Thank you all very much for the insights on the double and extra hours computation. I was able to correct my code and get it to run properly!!!

 

Now you need to split the homework grade with all of us ;)

  • 0
  On 06/04/2015 at 01:31, ajua said:

Now you need to split the homework grade with all of us ;)

 

I'll surely share my grade with the community. You guys rock!!  :D

 

 

  On 06/04/2015 at 01:41, Circaflex said:

man, i remember this exact problem on my business c# class final exam; crazy how many institutions reuse problems and examples for exams and homework

 

That's nuts, I guess they figure if its not broke, don't fix it. 

  • Like 2
  • 0
  On 06/04/2015 at 12:03, thehappygoldenlady said:

I'll surely share my grade with the community. You guys rock!!  :D

 

 

 

That's nuts, I guess they figure if its not broke, don't fix it. 

yea, i bet they share similar publishers/authors who have test bank questions, heck i just googled your problem and someone has a youtube video up on it as well, https://www.youtube.com/watch?v=qz7REN1qS6o, crazy

This topic is now closed to further replies.
  • Posts

    • It's a Developer Beta 1 not even a Public or User Beta, I doubt any of the design is 100% finalized yet.
    • Was going to comment the same thing. It's SO annoying to have to go back to settings every time I install something new or some apps like discord update and the icon is hidden again.
    • XRECODE3 1.167 by Razvan Serea xrecode3 is a converter and audio-grabber which allows you to convert from mp3, mp2, wma, aiff, amr, ogg, flac, ape, cue, ac3, wv, mpc, mid, cue ,tta, tak, wav, wav(rf64), dts, m4a, m4b, mp4, ra, rm, aac, avi, mpg, vob, mkv, mka, flv, swf, mov, ofr, wmv, divx, m4v, spx, 3gp, 3g2, m2v, m4v, ts, m2ts, adts, shn, tak, xm, mod, s3m, it, mtm, umx, mlp to m4a, alac, ape, flac, mp3, mp4 (using NeroAAC), ogg, raw, wav, wav(rf64), wma, WavPack, mpc, mp2, Speex, ofr, ac3, aiff, tak, snd and Shorten formats. Command Line parameters are supported. XRECODE3 features: Works on XP, Vista, Windows 7, Windows 8, 10 32/64 bit versions and under Wine. Parallel conversion by utilizing power of multi-core CPUs. Support of embedded CUE sheets (for FLAC, WavPack, APE and TAK files). Support of mp4, mka chapters (can split mp4, mka by chapters to any supported format). Built-in Metadata editor with Cover Art support. Has support for LossyWav. Supports portable mode. Merge input files to one large audio file and create CUE sheet. Converting to many formats at once using "Multiple" output mode. Grabbing of multi-channel Audio CDs to the desired format at once. Informative and resizable UI suited even for netbooks. Extracting audio from flv, avi, mov etc. video files (multiple audio streams are supported). Can export/import Metadata to/from external file. Support for 24/32bit audio files. Multilanguage support. Currently program is available in Dutch, English, French, Japanese, Korean, Polish, Russian, Hungarian, Italian, Spanish, Spanish Traditional, Swedish, Brazilian Portuguese, German, Finnish, Bulgarian, Czech, Danish and Chinese (simplified) languages. What's new in XRECODE3: Native 64bit support. Added support for DSD/DST and DFF formats (including handling of SACD ISOs). Added option to extract audio without transcoding. Added option to encode several files to one multi-channel file. Added option to split file into individual track-per-channel for all available output formats. Added option to merge files per folder. Output and Metadata settings are now output format specific. Enhanced Metadata settings. Added support for multiple Cover pictures in Metadata editor. Added 32bit int/float output for formats which support them (e.g. WAV). Added dithering option in Output Settings. Added option to use EBUR128 in Normalize. Added option to Album Mode Normalize. Added option to configure Matrices under Output Settings. Added more output file pattern elements. Tabbed UI. CUE files are now displayed more nicely. Enhanced Shell Extension. XRECODE3 1.167 changelog: Added option to handle YEAR and DATE tags (under Settings/Metadata/Advanced). Updated to the latest qaac (2.85). Download: XRECODE3 v1.167 (64-bit) | Portable | ~30.0 MB (Shareware) Download: XRECODE3 v1.167 (32-bit) | Portable Link: XRECODE3 Homepage | XRECODE3 Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Hasleo Disk Clone 5.2.2.1 by Razvan Serea Hasleo Disk Clone is a free and all-in-one disk cloning software for Windows 11/10/8/7/Vista and Windows Server that can help you migrate Windows OS to another disk, clone one disk to another disk or clone one partition to another location quickly and efficiently. Completely Free Windows Migration and Disk/Partition Cloning Software Migrate Windows from one disk to another without reinstalling Windows, apps. Clone one disk to another and makes the data on 2 disks are exactly the same. Clone a partition to another location without losing any data. Easily adjust the size and location of the destination partition. Convert MBR to GPT or convert GPT to MBR by cloning. Creation of Windows PE emergency disk. Extremely fast cloning speed and multi-language support. Supported OS: Windows Vista/Server 2008 or later, fully compatible with GPT and UEFI. Note: Hasleo Disk Clone 5.2.2.1 changelog is not yet available. Download: Hasleo Disk Clone 5.2.2.1 | 28.8 MB (Freeware) Link: Hasleo Disk Clone Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Shouldn't using "High Performance" mode prevent c-states from initializing? Maybe AMD hasn't built a proper power plan for their x3d processors like they used to for their ryzen chips.
  • Recent Achievements

    • First Post
      Johnny Mrkvička earned a badge
      First Post
    • Week One Done
      viraltui earned a badge
      Week One Done
    • One Month Later
      serfegyed earned a badge
      One Month Later
    • Dedicated
      firey earned a badge
      Dedicated
    • Dedicated
      fettermanj earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      634
    2. 2
      ATLien_0
      229
    3. 3
      Michael Scrip
      218
    4. 4
      Xenon
      149
    5. 5
      Steven P.
      140
  • Tell a friend

    Love Neowin? Tell a friend!