Lecture 9:  Iteration

Activity:



We just saw how loops are created in today's lecture.  This activity will give you experience with writing loops and thinking about loops in your programs.

Suppose you and a friend both work at the local grocery store.  The boss gives you two choices of how you will be paid.  Here are the choices:

Choice 1:  The boss will pay you 1 cent the first day, 2 cents the second day, 4 cents the third day, 8 cents the fourth day, and so on.  Each day your salary will be double of your previous day's salary.

Choice 2:  The boss will pay you $50.00 per day.

Since you want to make the most money, you decide to write a C program that calculates the number of days you need to work for Choice 1 to be better than Choice 2.  Suppose you take Choice 1 and your friend takes Choice 2.  Write the necessary C code to print out the number of days you need to work in order for your total salary to surpass your friend's total salary.  Like all programs, it is necessary to solve the steps of formulating the problem and describe the algorithm.

Problem Specification:
 
 
 
 
 

The Algorithm:
 
 
 
 
 
 
 

The C Program: