Help with calculating program

how do you code setting your output to a currency format, percent with two decimal spots, and regular decimal spots?
Last edited on
One way is using ostream manipulators:
 
cout << fixed << setprecision(2) << (float) yournumber;

and if you need the numbers to be right-aligned in a column you can set the width with:
 
cout << setw(10);

BTW, these manipulators need you to include the <iomanip> header.
So How would I fix the following?

#include <iostream>
#include <conio.h>

using namespace std;

int main ()
{

float principal,erate,crate,intrest,ctime,etime;
cout << "Please enter the amount of Principal: ";
cin >> principal;
cout << "Please enter the annual intrest rate: ";
cin >> erate;
crate = erate / 100;
cout << "Please enter how many years taken to pay back loan: ";
cin >> etime;
ctime = etime * 12;
intrest = principal * crate * ctime;
cout << "Principal: " << principal << "\n";

^ Make this a currency with two decimal places.

cout << "Annual Intrest Rate: " << crate << "\n";

^ Make this a percentage with two decimal places

cout << "Number of months: " << ctime << "\n";

cout << "Intrest Earned: " << intrest;

^Make this a currency with two decimal places
getch();
return 0;
}
Topic archived. No new replies allowed.