Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you complete the code below to satisfy the requirements of both the minimum and the challenge sections?? Assignment 2 - Advanced C Code Template

Can you complete the code below to satisfy the requirements of both the minimum and the challenge sections??

Assignment 2 - Advanced C Code Template

Write a program that will prompt the user for information to determine simple interest earned based on a given principle, interest rate, and time over years. You can do the minimum and receive up to 85 points or step up the challenge and get up to 100 points. Note that in my template, I am having IDEOne use the C++ compiler option. Any C program will compile just fine within a C++ compiler. We will learn more about C++ next week!

Minimum: (up to 85 points)

Start with a code template I've created already at: http://ideone.com/bz9Kzn. It even contains the input that we used from Homework Assignment 1. Just click the "fork" link at the top left hand corner of the IDEOne screen and you will have your very own code to get started.

I've also included the same template below that I've color coded so you know exactly what you need to update to get it to work. Look for the comment items in PURPLE that start with "TO DO" which indicate the places where you need to add your own code in order to make this work. It provides step by step details of exactly what you need to do. Most of the code you'll need is already in homework assignment 1. In reality, you only need to add three lines of code to the Calculate_Simple_Interest function.

The code below will compile and run with no modifications ... it will just return 0 for the simple interest until you add the right code into the Calculate_Simple_Interest function below. Add the same three input values (for principle, rate, and time) into the "stdin" area of IDEOne ... just like you did for homework 1. That way you can verify that it works.

4500 0.095 6 

Hint - Some of the code you can borrow from the challenge code below ... at least two of the statements (the first and the third one that I highlighted in green for you :) To recap:

  • Start with the template provided below.
  • Add the missing code for the assignment and/or challenge assignment, reuse code as needed (most of it is found below or in last week's assignment)
  • Add the three data values into the stdin area of IDEOne for use as your input
  • Submit the homework for grading when done

#include  /***************************************************************** ** Function: Calculate_Simple_Interest ** ** Description: Simple Interest is the amount of interest ** calculated by using the formula: ** ** interest = (P * R * T) ** ** where P is the principle, r is the rate, and t ** is the time of the investment ** ** This function will return the simple interest ** calculated based upon it being passed the principle, ** rate, and time. ** ** Parameters: Principle - The original principal to start with ** Rate - The rate of interest. If you wanted ** 9.5 percent it would be passed as 0.095 ** Time - The time in years ** ** Returns: Interest - The amount of simple interest earned ** ********************************************************************/
 
float Calculate_Simple_Interest (float principle, float rate, float time) 
{ 
 /* You will only need to create three simple statements here ... */ 
 /* No other statements are needed. */ 
 /* TO DO: Step 1) Define a local variable of type float to hold the interest */ 
 /* TO DO: Step 2) Calculate simple interest earned - Determine the interest using */ /* the values in the parameters: principle, rate, and time .... */ /* and assign that value to the local variable you created in step 1 */ /* that holds the interest */ /* .... Hint: This statement is right in the first homework */ 
 
 /* TO DO: Step 3) Add a return statement to return the interest calculated to main */ 
} /* end Calculate_Simple_Interest */ 
int main (void) 
{ 
 float interest; /* The interest earned over a period of time */ float principle; /* The amount being invested */  float rate;  /* The interest rate earned */  float time; /* The years of the investment */ 
 /* Initialize the interest value */ interest = 0;
 /* Enter values needed to determine interest */ printf (" Enter your principle value: "); scanf ("%f", &principle); 
 
 printf (" Enter the rate: For example 9.5 percent would be .095: "); scanf ("%f", &rate); 
 
 printf (" Enter the period of time of your investment: :"); scanf ("%f", &time); /* call simple interest function and print the interest calculated to the screen */
 interest = Calculate_Simple_Interest (principle, rate, time); 
 /* print the simple interest earned to the screen */  printf (" The total simple interest earned is: $%8.2f ", interest); 
 /* Challenge TO DO: Step 1) Call the Calculate_Compound_Interest function */ /* Challenge TO DO: Step 2) Print the compound interest to the screen */
 
 
 return (0); /* indicate successful completion */
 } /* end main */ 

Minimum Sample Output

The output when just the simple interest function is called within the minimum assignment would look like this:

Enter your principle value: Enter the rate: For example 9.5 percent would be .095: Enter the period of time of your investment: The total interest earned is: $ 2565.00

Challenge: (to receive full credit: 100 pts)

Can you also add and call a function to calculate Compound Interest? Start with my challenge template that includes everything you need at: http://ideone.com/s1zZoF. Like the other template, click the "fork" link at the top left hand corner of the IDEOne screen and you'll have your very own version to work with, including the recommended input to use.

You'll need to use the "pow" function in the C Math Library that will raise a value to a specific power. To use it, you will need to include the math.h file in addition to the stdio.h file (I've added this already to the template). #include /* for the pow function */ Using the challenge template above, just fill in the missing code sections that start with "TODO" just like you did for the minimum assignment. The template code will compile without any changes, but your job is to add the missing code to get everything to work. Good Luck!

/***************************************************************** ** Function: Calculate_Compound_Interest ** ** Description: Compound Interest is the amount of interest ** calculated by using the formula: ** ** interest = (P * pow (1.0 + r, t)) - P ** ** where P is the principle, r is the rate, and t ** is the time of the investment ** ** This function will return the compound interest ** calculated based upon it being passed the principle, ** rate, and time. ** ** Parameters: Principle - The original principal to start with ** Rate - The rate of interest. If you wanted ** 9.5 percent it would be passed as 0.095 ** Time - The time in years ** ** Returns: Interest - The amount of compound interest earned ** ********************************************************************/ float Calculate_Compound_Interest (float principle, float rate, float time) { /* Challenge Step 1) define a local variable of type float to hold the interest */ float interest; /* Challenge TO DO: Step 2) calculate compound interest earned ... */ /* Set interest variable to the right formula value, see above */ /* Challenge Step 3) return the interest calculated back to the calling function */ return (interest); } /* end Calculate_Compound_Interest */

Challenge Sample Output

The output when both the simple interest function AND the compound interest is called within the challenge assignment would look like this:

Enter your principle value: Enter the rate: For example 9.5 percent would be .095: Enter the period of time of your investment: The total simple interest earned is: $ 2565.00 The total compound interest earned is: $ 3257.06

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

How are icebergs a factor in sedimentation of glacial debris?

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

6. Does your speech have a clear and logical structure?

Answered: 1 week ago