a Create the logic for a program that calculates and display

a. Create the logic for a program that calculates and displays the amount of money you would have if you invested $5000 at 2 percent simple interest for one year. Create a separate method to do the calculation and return the result to be displayed.

b. Modify the program in Exercise 3a so that the main program prompts the user for the amount of money and passes it to the interest-calculating method.

c. Modify the program in Exercise 3b so that the main program also prompts the user for the interest rate and passes both the amount of money and the interest rate to the interest-calculating method. Write pseudocode. Submit only the final version of the program after you complete part c). Do not submit three different programs for this exercise.

Here\'s what I have so far...

Declarations
num balance
num PRINCIPAL = 5000
num INTEREST_RATE = 0.02
balance = PRINCIPAL * (1 + INTEREST_RATE)

Solution

#include <stdio.h>

double CalculateBalance(double Principal,double Interest_Rate)
{
double Balance;
Balance = Principal * (1 + Interest_Rate);
return Balance;
}

int main(void)
{
double Balance,Principal,Interest_Rate;
Balance = CalculateBalance(5000,0.02); // a.hardcoded values passed
printf(\"\ Balance =%.2f\",Balance);

printf(\"\ Enter the Principal Amount\"); //b. Principal is inputted by user
scanf(\"%lf\",&Principal);

Balance = CalculateBalance(Principal,0.02);
printf(\"\ Balance=%.2lf\",Balance);


printf(\"\ Enter the Principal Amount\"); //Principal and Interest_Rate are inputted by user
scanf(\"%lf\",&Principal);
printf(\"\ Enter the interest rate\");
scanf(\"%lf\",&Interest_Rate);

Balance = CalculateBalance(Principal,Interest_Rate);
printf(\"\ Balance=%.2lf\",Balance);

return 0;
}

output:

Balance =5100.00

a. Create the logic for a program that calculates and displays the amount of money you would have if you invested $5000 at 2 percent simple interest for one yea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site