
|
Operators Continued, Logical Expressions, Conditional StatementsToday we have gone through shorthand operators.
We then went over relational operators:
Conditional statements
if else conditional statements are covered today. Know how to use
each of the following:
Classwork program #1
Write a program that calculates the net pay for its
employees. The inputs are number of hours worked and
the hourly rate. The company you are writing this
program for is very generous and pays its employees time
and a half for all hours worked over 40. State tax is 10%
and the Federal tax is 23%. Net pay is computed by
subtracting both taxes from the gross pay.
Sample output of this program: What is your name? Enter the rate: Enter the hours: Name your net pay will be XX dollars!!! Nested if statements
if statements can go into one another. For example:
if (condition) {
statement1;
if (condition)
statement2;
}
else
statement3;
else if statements
With multiple conditions that cause different outcomes, you can use
else if statements. For example:
if (score > 89)
printf("grade = A");
else if (score > 79)
printf("grade = B");
else
printf("Bad grade");
Classwork program #2
Write a program to calculate the commission on a stock
Transaction. If the transaction amount is less than or equal to 5000
Dollars than the commission is 3%, but, there is a
Minimum commission of $35. If the transaction is greater
Than 5000 the commission is only 2% with no minimum
Commission. (Hint: use a nested if statement)
Sample output of this program: What is your transaction amount? Your commission will be $XX dollars! Homework Assignment
Your homework is to finish the two classwork programs (if you
are not done), and read Chapter 4 in your textbook.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||