Day 5
- Midterm and Lab Quiz coming up on April 21
- Reading: Read through Chapter 5
- Project 2 is due Monday night
- Lab 3 is due today at end of lab - I won't count off if you show me by beginning of lab on Tuesday
- Lecture Topics
- a bit more on selection
- What does the following function return when you call it with isWarmOrHot(78)?
int isWarmOrHot(int num)
{
if (num > 85)
if (num >90)
return 1;
else
return 0;
return -1;
}
while loops
Example: Write a function that accepts a positive int,
then returns the sum of the ints from 1 to the parameter
Example: Write a function that accepts a positive int,
then prints the even numbers in reverse order from the parameter down to 0
Example: Write a function that repeatedly prompts the user and reads
positive numbers until they enter a negative number. Return the
sum of the positive numbers entered.
Example: Modify the previous example to return the average of the
positive numbers entered.
In-class examples
kinds of loops - Examples
- counting loops
- sentinel-controlled loops
- end-of-file-controlled loops
- input validation loops
- general conditional loops
for loops
do-while loops