-
March 12th, 2014, 01:29 PM
#1
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.
-
March 12th, 2014, 02:57 PM
#2
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 '#'.
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 12th, 2014, 02:58 PM
#3
Re: Building a savings account program?
Originally Posted by JSkidds2294
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
-
March 12th, 2014, 03:31 PM
#4
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.
-
March 12th, 2014, 03:32 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|