Question

In: Computer Science

Hello, I am writing the initial algorithm and refined algorithm for a program. I just need...

Hello, I am writing the initial algorithm and refined algorithm for a program. I just need to make sure I did it correctly. I'm not sure if my formula is correct. I appreciate any help, thank you!

TASK: Write a program that will calculate the final balance in an investment account. The user will supply the initial deposit, the annual interest rate, and the number of years invested.

Solution

Description: Write a program that calculates the final balance in an investment account

Initial Algorithm:

Declare variables

Get initial deposit

Get annual interest rate

Get number of years invested

Calculate final balance

Display final balance in investment account

Data Requirements:(I/O)

Input – deposit

Input – interest rate

Input – number of years invested

Output – final balance

Formulas:

deposit * interest rate = growth rate

number of years * growth rate = final investment

         

Refined Algorithm:

Declare float deposit

Declare float interest rate

Declare float number of years

Declare float final balance

          Display “enter initial deposit”

Input deposit

          Display “enter interest rate”

                   Input interest rate

          Set growth rate = deposit * interest rate       

Set final investment = number of years * growth rate

Display “The final balance of your account will be”, final investment, “after”, number of years, “years”, EOL

Solutions

Expert Solution

I WROTE THE CODE IN C++ LANGUAGE

I ADD COMMENTS TO THE CODE FOR CLEAR UNDERSTANDING

CODE

#include <iostream>

using namespace std;

int main()
{
//variables declaration.
float deposit,interest_rate,no_years,growth_rate,total_interest,fin_balance;
  
//scanning input.
cout<<"enter initial deposit: ";
cin>>deposit;
cout<<"enter interest rate(%): ";
cin>>interest_rate; //interest_rate is given in percentage
cout<<"enter number of years: ";
cin>>no_years;
  
  
growth_rate=(deposit*interest_rate)/100; //calculate growth_rate.
total_interest=no_years*growth_rate; //calculate total_interest
fin_balance=total_interest+deposit; //calculate final balance.
  
  
//display results.
cout<<endl;
cout<<"initial deposit: "<<deposit<<endl;
cout<<"interest rate: "<<interest_rate<<endl;
cout<<"number of years: "<<no_years<<endl;
cout<<"total_interest: "<<total_interest<<endl;
cout<<"The final balance of your account will be "<<fin_balance<<" after "<<no_years<<" years ";

return 0;
}

OUTPUT:

SCREENSHOT OF THE CODE:

EXPLANTATION:

when taking interest rate in percentage

final balance = deposit + total interest.


Related Solutions

I have to write an initial algorithm and a refined algorithm for the following problem: Display...
I have to write an initial algorithm and a refined algorithm for the following problem: Display the square of numbers from 0 to some user inputted value. For example if the user enters 3 then the program will need to display the square of 0, 1, 2 and 3. Must use a counter loop. Must use 2 methods. One method that gets the number from the user and returns it. A second method is passed that number as a parameter...
hello, I am writing an article why pharmacists need to be utilized as precribers in the...
hello, I am writing an article why pharmacists need to be utilized as precribers in the U.S in effort to help accessibility for women to obtain birth control? any thoughts based on evidence? please provide reference of articles.
Hello I am Raj and I need assistance with this algorithm. Thanks . EX.17-15.ALGO Costs per...
Hello I am Raj and I need assistance with this algorithm. Thanks . EX.17-15.ALGO Costs per Equivalent Unit and Production Costs The following information concerns production in the Forging Department for November. All direct materials are placed into the process at the beginning of production, and conversion costs are incurred evenly throughout the process. The beginning inventory consists of $56,050 of direct materials. ACCOUNT Work in Process—Forging Department ACCOUNT NO. Date Item Debit Credit Balance Debit Credit Nov. 1 Bal.,...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
Hello, I need to convert this java array into an array list as I am having...
Hello, I need to convert this java array into an array list as I am having trouble please. import java.util.Random; import java.util.Scanner; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in); int[] data = new int[1000]; int count = 0; while (!choice.equals("No")) { int randomInt = 2 * (random.nextInt(5) + 1); System.out.println(randomInt); data[count++] = randomInt; System.out.print("Want another random number (Yes / No)? "); choice =...
Hello, I am in need of some assistance in interpreting the data for the two variables...
Hello, I am in need of some assistance in interpreting the data for the two variables I did in a t-test for in Excel. Variable 1 is Relationship with Direct Supervisor and Variable 2 is the Workplace Happiness Rating. I am supposed to write a 125- to 175-word summary of my interpretation of the results of the t test. t-Test: Two-Sample Assuming Equal Variances Variable 1 Variable 2 Mean 2.5 7.4 Variance 1.030612245 2 Observations 50 50 Pooled Variance 1.515306122...
Hello I need a small fix in my program. I need to display the youngest student...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
I just need 3 and 5. I am not sure what I am doing wrong. I...
I just need 3 and 5. I am not sure what I am doing wrong. I get different numbers every time. Superior Markets, Inc., operates three stores in a large metropolitan area. A segmented absorption costing income statement for the company for the last quarter is given below: Superior Markets, Inc. Income Statement For the Quarter Ended September 30 Total North Store South Store East Store Sales $ 4,800,000 $ 960,000 $ 1,920,000 $ 1,920,000 Cost of goods sold 2,640,000...
Hello, I am trying to write a C++ program that will do the following: Use the...
Hello, I am trying to write a C++ program that will do the following: Use the STL stack container in a program that reads a string, an arithmetic expression to be exact, one character at a time, and determines if the string has balanced parenthesis – that is, for each left parenthesis there is exactly one matching right parenthesis later in the string.                         Use the following strings to test your program. A+ B - C A * B / (C...
Hello! I am having trouble starting this program in Java. the objective is as follows: "...
Hello! I am having trouble starting this program in Java. the objective is as follows: " I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number. " my question is, how do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT