c++ how should I fix this?

Write your question here.

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

using namespace std;

int main()
{
double a[12];
double b[12];
double c[12];
cout <<"Output monthly balances for one year at 0.03\n";
cout << "Balances: Saver 1 $2000.00" <<" "<<"Saver 2 $3000.00\n";
for (int i=0, j=0,k=0; i<12, j<12, k<12; i++, j++,k++)
{
c[k]=k+1;
cout << "Month "<< c[k] <<": \n";
a[i]=2000*pow(1.0025,i+1);
cout<<showpoint<<std::fixed<<setprecision(2)<<"Saver 1 $" <<a[i]<<" ";

b[j]=3000*pow(1.0025,j+1);
cout<<"Saver 2 $" <<b[j]<<endl;
}
cout << "After setting interest rate to 0.04\n";
cout << "Saver 1 $"<<a[11]*(1+0.04/12)<<showpoint<<std::fixed<<setprecision(2)<<" ";

cout << "Saver 2 $"<< b[11]*(1+0.04/12)<<endl;
_getch();
return 0;
}


Unlike what I have expected, months are also appearing like 2.00, 3.00.

Can I make it appear as 2,3,4,5,...12?
However, the amount should show 2 floating point digits.
For example, 2150.00 2143.10
Try typecasting c[k] to int. The syntax for a typecast is:

typename(variable)

That should fix it, since currently month is double.
Topic archived. No new replies allowed.