setting up decimal places

I'm trying to get the output for this program into a specific format but i cant quite seem to get the decimal places to appear in one instance and in another it changes the number to a notation form.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  #include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

void ReadLoanInfo(int &Prin, int &Yea, int &PPY, float &Ra);
float MonthlyPayment (int Prin, int Yea, int PPY, float Ra);
void ShowTable (int Prin, int Yea, int PPY, float Ra, float MP);
void main()
{
	int Principle=0, Years=0, PaymentsPerYear=0;
	float Rate=0, PerMonth;
	char Continue;
	do{
	ReadLoanInfo(Principle, Years, PaymentsPerYear, Rate);
	PerMonth=MonthlyPayment(Principle, Years, PaymentsPerYear, Rate);
	ShowTable(Principle, Years, PaymentsPerYear, Rate, PerMonth);
	cout<<"To continue enter Y:";
	cin>>Continue;}
	while(Continue=='y'||Continue=='Y');
}

void ReadLoanInfo(int &Prin, int &Yea, int &PPY, float &Ra)
{
	cout<<"Please enter the Principle: ";
	cin>>Prin;
	cout<<"Please enter the Annual Intrest Rate: ";
	cin>>Ra;
	cout<<"Please enter the number of Years: ";
	cin>>Yea;
	cout<<"Please enter the payments per year: ";
	cin>>PPY;
}

float MonthlyPayment (int Prin, int Yea, int PPY, float Ra)
{
	float IR, Bottom, Base, MP;
	int Term;

	IR=Ra/12.0;
	Term=Yea*PPY;
	Base=IR+1;
	Bottom=(1-pow(Base, -Term));
	MP=Prin*(IR/Bottom);
	return MP;
}

void ShowTable (int Prin, int Yea, int PPY, float Ra, float MP)
{
	int NoP=Yea*PPY;
	cout<<"Principle---------->$"<<Prin<<endl;
	cout<<"Interest Rate------>"<<Ra*100<<"%"<<endl;
	cout<<"No. of Years------->"<<Yea<<endl;
	cout<<"Payments Per Year-->"<<PPY<<endl;
	cout<<"No. of Payments---->"<<NoP<<endl;
	cout<<"Monthly Payment---->$"<<setprecision(2)<<MP<<endl;
}

here is the output:
Please enter the Principle: 11000
Please enter the Annual Intrest Rate: 0.1
Please enter the number of Years: 4
Please enter the payments per year: 12
Principle---------->$11000
Interest Rate------>10%
No. of Years------->4
Payments Per Year-->12
No. of Payments---->48
Monthly Payment---->$2.8e+002
To continue enter Y:
how do I get the principle and monthly payment to show decimals?
First of all, int main(), not void main().

You can make it not display scientific notation by doing cout << fixed; somewhere in there.
http://www.cplusplus.com/reference/ios/fixed/
I see, that works thanks!
Topic archived. No new replies allowed.