Solved

Needs help in output

Posted on 2011-02-23
2
321 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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL400 max size 5 52
word0 challenge 3 56
listing all functions in JavaScript 19 98
Windows Service to Receive TCP Packets 4 30
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

11 Experts available now in Live!

Get 1:1 Help Now