Solved

Needs help in output

Posted on 2011-02-23
2
336 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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 …
Make the most of your online learning experience.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

717 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