Hello, and welcome. Now that we've finished our lectures on
decisions, the if statement and the switch statement,
I want to provide you with a little assignment, a little challenge.
So in this challenge you're going to create a c program that calculates your weekly pay.
This program should ask the user to enter the number of hours worked in a week
via the keyboard.
Program should display as output, the gross pay, the taxes and the net pay.
So the following basic assumptions should be made.
The pay rate is going to be 12 dollars an hour.
Overtime is any time you have more than 40 hours, you're going to get paid time and a half.
The tax rate is going to depend on how much money you make.
For the first 300 dollars that you make it's going to be 15%.
For the second 150 dollars 300 to 450, it's going to be 20%.
And for anything above 450, you're going to be
provided at the tax rate of 25%.
So the first thing you should notice is you're going to have to write a lot of decisions.
And the whole purpose of this assignment is to get you familiar with the if else statements.
So what I'm expecting for this assignment
is for you to first you're going to need an if else statement
to calculate the overtime.
So overtime is anything in excess
of 40 hours. So you're going to have to see if there's overtime. You're going to have to say if
the number of hours entered is a greater than 40, then they're going to get paid 18 dollars an hour.
Now you want to make sure that
they only get paid for the hours after 40.
So if you enter 45 is the number of hours worked,
you're going to get paid 12 dollars an hour for those first 40 hours.
And then for the other 5 hours, you're going to make 18 dollars an hour.
So you have to keep that in mind.
And then with the tax rates, you're going to have to have if statements. Because depending on
whether or not they made more than 300 dollars or made more than 450 dollars, you're going to have
additional tax rates. So if the if the user entered 45
and that means you have to calculate overtime pay.
What will end up happening for 45 hours, I think roughly the pay will be,
let's say, 12 dollars an hour times 40 is
480.
And then for those 5 extra hours,
you're going to get paid 18 dollars an hour,
that's 90 dollars. So 480 plus 90 is 570.
So you should display for the gross pay 570,
that would be an example run,
570 dollars for gross pay. Now the taxes
are going to be calculated different for that entire 570.
So for the first 300 that you make,
you're going to have a tax rate of 15%. So you want to tax 15% of 300.
And then from 300 to 450, which is 150 dollars, that's going to be taxed at
20%, only the 150.
And then if you make more than that, you're going
to tax the rate of 25%.
So don't confuse these tax rates.
The tax rates are different for each amount you make,
not for total.
So if you made 800 dollars that doesn't mean you paid 25% in taxes.
It means you paid 300 of that 800 as 15%,
150 of that 800 as 20%
and then 350 dollars of the remaining is 25%.
And that will force you to write if else statements.
So I wanted to make that clear as far as the output and what we're looking for.
So go over this. The requirements are pretty basic.
You're going to have to enter something via the keyboard for a number of hours.
First thing you want to do is you want to organize your program.
You want to constantly test, you want to use meaningful names.
And for the if statements, you want to indent. You want to indent all of your blocks so it makes it easier to read.
You should have noticed in all my lectures, all my examples I was indenting code.
Get in the habit of indenting blocks and adding new lines for readability.
But you can group this program into the problem-solving aspect.
First thing I would do is I would get the
user to enter the number and I would test it and make sure that's working.
The next thing I would do is I would just figure out the gross pay.
So the gross pay would basically just include figuring out the overtime if it's more than 40.
When I'm done with gross pay, I would test it like crazy make sure it works. Then I would move on to taxes
and I would test the taxes.
And then once I'm done with taxes,
I would figure out the net pay. The net pay is going to be the easiest part
because it's just going to be the gross pay minus the taxes.
But I hope at the end of this exercise, you're going to become
pretty adept at if statements. You'll at least understand the basics,
understand the else, understand when you need to add brackets
and understand how to make your code more readable by indenting and
using good variable names. So good luck. Thank you.