> double monthlyInterest = interest * 12;
Not divide by 12 ?
> double interest = 5.7;
I think this is 570%
Seems high to me.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
In order to allow the user to enter new data or quit, you will want to place all of your code after your variable declarations in a while loop. That way, the user can go through the program as many times as he or she wants:
#include <iostream>
#include <cmath>
#include <string>
using namespace std; int main ()
{
double principle = 0;
double interest = 5.7;
int term = 30 * 12;
double total;
double monthlyInterest = interest * 12;
bool validNum = false;
//create a yesNo variable to allow the user to select
//if her or she wants to keep using the program
string yesNo = "y"
while(yesNo == "y")
{
//contents of the program, then add question at the
//end asking user if they would like to use it again
}
Hope that helps!
-D
dgr231
Junior Poster in Training
76 posts since Aug 2009
Reputation Points: 55
Solved Threads: 7
Okay, I understand the the yes no part. But when i run the current loop i have it doesnt seem to work right. What is it i am doing wrong with it? I have tried so many different things, but i just cant seem to get it to work.
What exactly is the program doing that you don't want it to?
-D
dgr231
Junior Poster in Training
76 posts since Aug 2009
Reputation Points: 55
Solved Threads: 7
If you want fixed point then user
cout.setf(std::ios_base::fixed,std::ios_base::floatfield);
This will output number such as 1.2000000000 instead of
1.2e10
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Give me an input values and what the output value supposed to be.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Correct me if I'm wrong, but it seems like you have your monthly interest set up as 12 times your yearly interest, or 12 years worth of interest per month:
double monthlyInterest = interest * 12;
Shouldn't it be your yearly interest divided by 12 (1/12 of the yearly interest per month?):
double monthlyInterest = interest / 12;
Perhaps I'm wrong about that, but it seems like your problem may be stemming from there...
-D
dgr231
Junior Poster in Training
76 posts since Aug 2009
Reputation Points: 55
Solved Threads: 7
Right, note how on the code you just posted for the hard coded variables that you have monthlyInterest defined as the following:
double monthlyInterest = interest / 12
Whereas in the code you posted for the user-defined variables, you have monthlyInterest defined as follows:
double monthlyInterest = interest * 12
Those two definitions will yield drastically different results...
-D
dgr231
Junior Poster in Training
76 posts since Aug 2009
Reputation Points: 55
Solved Threads: 7