Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Future Investment Amount gives exponents - Need dollar amount

$
0
0
#include <iostream>
#include <cmath>
using namespace std;

int main ()
{

	double investmentAmount, annualInterestRate, monthInterestRate;
	double accumulatedValue;
	int numberOfYears;

	cout << "Enter the amount of investment [for example, 15000]:  ";
	cin >> investmentAmount;

	cout << "Enter the annual interest rate [for example, 6 percent].  ";
	cin >> annualInterestRate;

	monthInterestRate = annualInterestRate / 1200;
	cout << "Enter number of years invested:  ";
	cin >> numberOfYears;

	accumulatedValue = investmentAmount * (1 + monthInterestRate) * (pow(double(numberOfYears), 12.0));

	cout << "The expected future value on the investment is $" << accumulatedValue << endl;

	return 0;
}



Everytime I run the code and input anything over 1+ year, I get an answer with exponents. Is there any possible way to get a dollar amount with two decimal places only? If so, what code do I need to use to achieve a result with two decimal places? I'm very new to C++ and would appreciate any and all help given.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>