Building a savings account program?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Building a savings account program?

  1. #1
    Join Date
    Mar 2014
    Location
    Warwick, RI, USA
    Posts
    3

    Building a savings account program?

    #include "stdafx.h"
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;


    int _tmain() {

    // declare variables

    int principal = 1000;
    double rate = .03;
    int years = 1; //counter
    double balance = 0.0;

    // Begin loop


    do{
    balance = principal * pow(1 + rate, years);
    cout << "year " << years << ":" << endl;
    cout << " $" << balance << endl;
    years += 1; //update years counter

    } while (years < 6);

    system("pause");
    return 0;
    }


    //This is the end of the initial program...

    I need to modify the program to use annual interests rates of 3%, 4%, and 5%.

    After that I need to modify the program to make it so the user enters the dollar amount of the deposit, the interest rate or rates, and the number of years.

    I'm a design student at New England Tech but before we can go full design they want to make sure we know for sure if we want to be a designer or a programmer and so we need to take C++ classes which I suck at so any help would be appreciated.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,866

    Re: Building a savings account program?

    First, when posting code please use code tags to make the code readable. Go Advanced, select the code and then click '#'.

    Code:
    double rate = .03;
    3% is really 3 / 100 which is .03. So you should be able to change the interest rate to 4%, 5% or any other required interest rate.

    For the user to enter data from the keyboard in c++, the stream cin is usually used (as opposed to cout to display). For example
    Code:
    double amount;
    cin >> amount;
    will obtain the input from the user of type double and store it in the variable amount.

    For more info about cin see http://www.cplusplus.com/reference/iostream/cin/

    You might also like to look at these sites
    http://www.cplusplus.com/doc/tutorial/
    http://www.learncpp.com/
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,006

    Re: Building a savings account program?

    Quote Originally Posted by JSkidds2294 View Post
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;
    
    
    int _tmain() {
    
    	// declare variables
    
    	int principal = 1000;
    	double rate = .03;
    	int years = 1;       //counter
    	double balance = 0.0;
    
    	// Begin loop
    
    
    	do{
    		balance = principal * pow(1 + rate, years);
    		cout << "year " << years << ":" << endl;
    		cout << "   $" << balance << endl;
    		years += 1;     //update years counter
    
    	} while (years < 6);
    
    	system("pause");
    	return 0;
    }

    //This is the end of the initial program...

    I need to modify the program to use annual interests rates of 3%, 4%, and 5%.
    Fist you have to use Code tags. Otherwise your code is very hard to read/understand.
    Second, what is the problem to "modify the program to use annual interests rates of 3%, 4%, and 5%"?
    Third, about homework.
    Victor Nijegorodov

  4. #4
    Join Date
    Mar 2014
    Location
    Warwick, RI, USA
    Posts
    3

    Re: Building a savings account program?

    Sorry it was my first time posting on this site also I figured out the problem out before this thread became visible. I was also just asking for tips or examples not the HW done for me. Sorry for the confusion.

  5. #5
    Join Date
    Mar 2014
    Location
    Warwick, RI, USA
    Posts
    3

    Re: Building a savings account program?

    Also thank you to 2kaud for try to help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)