| jeaninem71 (7) | |
|
I am going to need to put this in two posts, the assignment first, the code second. I am getting errors that I cannot use pow as a function, what am I doing wrong? I am not even sure if I have the calculations right. Also, I am not allowed to use one letter variables so how to turn for example the letter M into choiceM? Directions and requirements: Program #2 Write a program to compare the return from a yearly compounded interest calculation (i.e. figured and added to the balance annually) to interest that is compounded monthly, weekly, or daily. The program should: • Use double precision floating point variables, where floating point variables are used. • Let the user choose from a menu which comparison to make (compounded monthly, weekly, or daily). A fourth menu choice, exit the program, should be included on the menu. • Ask the user for a beginning balance, an annual interest rate, and a term in years. o Error check each of the above items, one at a time, as they are entered. All of them must be at least 1. Additionally, annual interest cannot be more than 50%, and the term should not be more than 100 years. For each item, re-prompt the user until a valid value is entered. Error messages should tell the user what values are valid. • Display the total return computed with annual compounding versus interest compounded monthly or weekly or daily, formatted as shown in the Sample Run. o The total compounded returns must be calculated using nested loops, NOT banking interest formulas. You will compute the interest and add it to the balance each time you loop. o Calculate annual interest by adding annual interest to the running balance every year. o Calculate monthly interest by adding monthly interest (use 1/12th of the annual interest rate) to the running balance every month for 12 months per year. o Calculate weekly interest by adding weekly interest (use 1/52nd of the annual interest rate) to the running balance every week for 52 weeks per year. o Calculate daily interest by adding daily interest (use 1/365th of the annual interest rate) to the running balance every day for 365 days per year. • Loop back to the menu, and continue until the user chooses EXIT from the menu. o The program should ONLY exit when the user chooses EXIT from the menu. o Do NOT ask the user if s/he wishes to run the program again – just redisplay the menu each time until EXIT is chosen. In addition to main, your program must contain a minimum of four additional functions with parameters and/or return values. You should try to use functions to reduce code duplication, when the code is similar in multiple places. HINT: When you consider how to break this program into functions, think about how program 1 was divided up: • At least one function to read input • At least one function to do calculations • At least one function to display output Use of global variables is NOT allowed. The functions should use parameters to pass required data to each function. Remember to pass all input parameters by VALUE, and pass all output parameters by REFERENCE. Display dollar figures to 2 decimal places and the interest rate to 3 decimal places. Sample Run When the user presses a key to continue, the program will loop and re-display the menu. The program will exit when the user chooses EXIT from the menu. This program demonstrates the benefits of compounding interest. Compare Annual Compounding to: M - Monthly Compounding W - Weekly Compounding D - Daily Compounding E - Exit Program Enter choice from Menu above: w Enter your beginning balance: 5555.55 Enter an annual interest rate: 5.5 Enter a term in whole years: 5 ------------------------------------------------ RESULTS ------------------------------------------------ Beginning Balance: 5555.55 Return after 5 years at 5.500% interest annually: Return Ending Balance Compounded Yearly: $ 1705.33 $ 7260.88 Compounded Weekly: $ 1757.44 $ 7312.99 ------------------------------------------------ Press any key to continue . . . When the user presses a key to continue, the program will loop and re-display the menu. The program will exit when the user chooses EXIT from the menu. | |
|
|
|
| jeaninem71 (7) | |||
Here is the code for the above program:
| |||
|
|
|||
| TheIdeasMan (1564) | |
|
The pow function takes 2 arguments - x to the power of y. Also, consider the use of a bool variable to help control the redisplay the display of the menu. Edit: I would have separate functions for the weekly, daily & monthly calculations - and call these from within the switch. This will save the repeated logic in the getCalculations function - and might cut down on the number of args to functions. HTH - GOOD LUCK !!!! | |
|
Last edited on
|
|