## Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

• Help others & share knowledge
• Earn cash & points
Solved

# Needs help in output

Posted on 2011-02-23
329 Views
Hi guy: Can any one please help me that why it shows only year1 why it not shows the rate of the rest of the years in the program ? Thanks.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
int principal = 1000;
int years = 1;
double balance = 0.0;
double rate = 0.03;
do
{
cout << "Year" << years << ":" << endl;
while (rate < .06)
{
balance = principal * pow(1 + rate, years);
cout << fixed << setprecision(0);
cout << " Rate " << rate * 100 << "%: \$";
cout << setprecision(2) << balance << endl;
rate +=.01;
}
years +=1;
}      while (years < 6);
system("Pause");
return 0;
}
0
Question by:mustish1

LVL 16

Accepted Solution

sjklein42 earned 500 total points
ID: 34964061
You need to reset rate and balance before going into the loop the second time.
``````#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
int principal = 1000;
int years = 1;
do
{
double balance = 0.0;
double rate = 0.03;
cout << "Year" << years << ":" << endl;
while (rate < .06)
{
balance = principal * pow(1 + rate, years);
cout << fixed << setprecision(0);
cout << " Rate " << rate * 100 << "%: \$";
cout << setprecision(2) << balance << endl;
rate +=.01;
}
years +=1;
}      while (years < 6);
system("Pause");
return 0;
}
``````
0

Author Closing Comment

ID: 34964079
Thanks.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…