Day 4
- Reading: Read through Chapter 5 by Thursday
- Project 2 assigned
- Lab 3 assigned today
- Lecture Topics
- if/then/else
- compound statements/blocks use braces
- conditions
- relational and equality operators: <, >, <=, >=, ==, !=
- logical operators: &&, ||, !
- Example: write a function that returns the smallest of three numbers
int getSmallest(int num1, int num2, int num3)
{
int smallest;
smallest = num1;
if (num2 < smallest) {
smallest = num2;
}
if (num3 < smallest) {
smallest = num3;
}
return smallest;
}
Example: write a function that returns 'B' if two numbers are either equal or both are negative, and returns 'G' otherwise
Example: write a function that prints "Good job!" if a score is above 90,
"Amazing!" if a score is above 95, and "Wow!" if a score is above 98
using 0 as false, 1 (or any nonzero value) as true
Example: write a function that determines if a number is odd
operator precedence (Table 4.6 p. 162 in book)
short-circuit evaluation
complementing a condition: !(x == 4) ====> x != 4, or !(x < 4) ====> (x >= 4)
DeMorgan's Theorem (p. 168 in text)
switch
Example: write a function to print the day of the week name, given the first char
Example: write a program that reads up to three item prices, calculates their sum, gives a discount of 10% if the sum is over $100, and 15% if the sum is over $500, then adds 8.75% sales tax, finally printing the total, discounted total, tax, and final bill. Ask the user if they want to enter another item. If they enter a negative item price, give them a second chance to enter the item price.
- Write header comment
- Write main and makefile
- Write testCases() with one test
- Write a function to make test pass
- Write a second test
- Revise function to make tests pass
- Refactor
- Write I/O in main()