Solved

Needs help in output

Posted on 2011-02-23
2
331 Views
Last Modified: 2012-05-11
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
Comment
Question by:mustish1
[X]
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
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
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;
}

Open in new window

0
 

Author Closing Comment

by:mustish1
ID: 34964079
Thanks.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question