So I have this code I'm trying to do for writing out compound interest for a given amount over months. When I compile it all the months and number crunches come out on the same line and I can't figure out why the break; in the if statement isn't ending the lines. Any suggestions?
#include <iomanip>
#include <iostream>
#include <string>
usingnamespace std;
#include <cmath>
#include <ctime>
int main()
{
double p; // principal at beginning of period
double r; // rate of annual interest (as decimal)
double a; // amount at end of period
int m; // month index
string s; // month name (abbreviated)
cout << endl;
cout << "Monthly Compound Interest Program" << endl;
cout << "---------------------------------" << endl;
cout << "When prompted, enter starting amount" << endl;
cout << "(as positive number, with no dollar" << endl;
cout << "sign of commas)" << endl << endl;
cout << fixed << showpoint;
cout << setprecision(2);
while(true)
{
cout << "Starting amount?: ";
cin >> p;
cout << endl;
if (p > 0)
break;
else;
cout << '\a';
cout << "Must be positive number; try again" << endl << endl;
}
cout << " E n d i n g B a l a n c e" << endl;
cout << " ----------------------------" << endl;
cout << "Mon. 2% 4% 6%" << endl;
cout << "---- -------- -------- --------" << endl;
for (m = 1; m <= 12; m++)
{
switch (m)
{
case 1:
s = "Jan. ";
break;
case 2:
s = "Feb. ";
break;
case 3:
s = "Mar. ";
break;
case 4:
s = "Apr. ";
break;
case 5:
s = "May ";
break;
case 6:
s = "Jun. ";
break;
case 7:
s = "Jul. ";
break;
case 8:
s = "Aug. ";
break;
case 9:
s = "Sep. ";
break;
case 10:
s = "Oct. ";
break;
case 11:
s = "Nov. ";
break;
case 12:
s = "Dec. ";
break;
}
cout << s;
for (r = .02; r < .08; r = r + .02)
{
a = p * pow ( 1 + r / 12.0, m);
cout << setw(10) << a;
}
}
}