Using switch case and loop in one problem.

4 views (last 30 days)
This is an interest problem. I have to create a program where the user needs to input an initial deposit amount, the interest rate, and select what the frequency of the compounding is (monthly, quarterly, semiannually, or annually) using a menu. I then need to use a for loop to determine what the amount of money that was accumulated in one year.
so far I have:
I=input('Enter initial deposit amount.');
R=input('Enter interest rate');
freq=menu('Select desired frequency of compounding','Monthly','Quarterly','Semianually','Annually');
I am not sure how to use a switch case and a for loop along with these user inputs. Any suggestions or at least guidance?

Answers (1)

Star Strider
Star Strider on 22 Apr 2014
I suggest that you write the for loop first to be sure it works and calculates the compound interest correctly.
Then read the documentation on switch, case, otherwise and get that working.
Then put them together to create you finished assignment.
  5 Comments
Matthew Quinones
Matthew Quinones on 22 Apr 2014
now how about for the other frequencies? Do I have to do a for loop for each one?
Star Strider
Star Strider on 22 Apr 2014
Not necessarily. Once you have the interest rate R and the compounding period freq, you can run the loop once at the end of switch...case...end block. Then print the result.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!