The assignment asks to input these values:
D = Investment Amount (5000)
P = Interest (5.25)
Y = Number of Years (2.25)
M = Conversions/Year (4)
It tells me to use float for interest, and int for the rest.
I have to use this formula to calculate the Maturity value (S)
S = D ( 1 + P/M) to the power of YM
Using the data above S is suppose to equal 5622.60
When I debug I get 5065.62.
I think I have made an error in typecasting int to double or float to double
Code:
// MaturityCalc.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int m, y, d;
double s;
float p;
//keyboard input
cout << "Please input the following information";
cout << endl;
cout << "Investment Amount: ";
cin >> d;
cout << endl;
cout << "Interest Rate: ";
cin >> p;
cout << endl;
cout << "Conversions/Year: ";
cin >> m;
cout << endl;
cout << "Number of Years: ";
cin >> y;
cout << endl;
//end keyboard entry
y = y * m;
p = 1 + (p/100)/m;
pow ((double) p , (double)y);
s = d * p;
cout << "This is the result: " << (double)s;
system ("pause");
return 0;
}
Note: This is my second assignment, first week of C++, I have very little knowledge of this.
Any help is appreciated.