Solved

Needs help in output

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now