Attention: PROnetworks has upgraded our forum from phpbb2 to phpbb3!!

Please head over to our new converted forum at: http://www.pronetworks.org/forums/

This old forum will remain 'read-only' until approximately February 2009. We look forward to seeing you at the new forum!
Author Message
lowellabraham
PostPosted: Wed Mar 26, 2008 1:52 am Reply with quote

PRO Level 13
 
 


Joined: 12 Sep 2004
Posts: 651
Location: Long Island, New York
hey guys,

let me first post the code, so you know what I am talking about...
It is a bit long.

Code:
/*
Write an interactive C++ program to prompt the user for an amount of money to be invested and an interest rate.
The given amount of money is to be invested at the interest rate indicated (with annual compouding), and the
number of years until the amount of money is doubled is to be determined. Display on the screen a list of values
of this investment at the beginning of each year, interest earned during the year and the value of the investment
at the end of the year until the investment (at least) doubles.

  Sample input might be $1000 invested at a rate of 5%. You will input the interest rate as a percentage.
  A partial chart follows:

  Year      Year Begin $      Interest      Year End $
  1         1000.00            50.00         1050.00
  2         1050.00            52.50         1102.50
 

  This chart would continue until the amount of the money at the end of a year is double the original amount.
 
  Use a while statement to implement the loop
*/

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

void main()
{
   int year;
   float interest, balance, investedamount;

   cout << setiosflags (ios :: fixed | ios :: showpoint);
   cout << setprecision (2);

   cout << "Please enter the amount of money to be invested: $";
   cin >> investedamount;

   cout << "Please enter the percentage of interest rate: ";
   cin >> interest;
   
cout << endl;

   cout <<"The Amount you have invested is $"<<investedamount<<endl;
   cout <<"The Interest Rate on investment is "<<interest<<"%"<<endl;
   
   cout <<endl;

   interest = interest/100;
   balance = investedamount;
   year = 0;
   
   cout << "Year/s" <<"           Year Begin $"<< "        Interest"<<"         Year End $"<<endl;

   cout << endl;

   while (balance <= investedamount*2)

   {
      balance = interest * balance + balance;
      year=year+1;
      
      cout <<setw(3)<< year; // Year/s
      cout <<setw(22)<< balance; // Year Begin $
      cout <<setw(19)<< interest*balance; // Interest
      cout <<setw(23)<< balance+interest*balance<<endl; // End Year $
      }

   cout <<endl;
}


ok, so according to the sample that my professor gave, Year 1 should have a Begin amount of $1000.00

I am not getting 1000.00 Year Begin $ for Year1

This is what I am getting..
Code:

  Year      Year Begin $      Interest      Year End $
  1           1050.00             52.50         1102.50
  2           1102.50             55.13         1157.63


it is suppose to look like this..

Code:

  Year      Year Begin $      Interest      Year End $
  1           1000.00             50.00         1050.00
  2           1050.00             52.50         1102.50
  3           1102.50             55.13         1157.63



can anyone help! i'd really appreciate it...
thank you soo much! notworthy
 
Back to top
NoReflex
PostPosted: Wed Mar 26, 2008 9:05 am Reply with quote

PRO Level 12
 
 


Joined: 17 Nov 2004
Posts: 609
Location: Romania
I think you should print the first state before making the operations in the while loop. You could try something like this :
Code:

   while (balance <= investedamount*2)

   {
      cout <<setw(3)<< year; // Year/s
      cout <<setw(22)<< balance; // Year Begin $
      cout <<setw(19)<< interest*balance; // Interest
      cout <<setw(23)<< balance+interest*balance<<endl; // End Year $

      balance = interest * balance + balance;
      year=year+1;

      }

   cout <<endl;


You should also initialize the value of the "year" variable with 1 : "year = 1;".
I can't verify this right now but I guess it should work!
Good luck!

Best wishes,
John!
 
Back to top
lowellabraham
PostPosted: Wed Mar 26, 2008 9:21 am Reply with quote

PRO Level 13
 
 


Joined: 12 Sep 2004
Posts: 651
Location: Long Island, New York
noReflex! thank you soo much dude! you the man! You really help me out here smile

Image Hosted by ImageShack.us
 
Back to top
Back to top
Index >> Webmaster Domain & Code Room >> Help with C++ Home Work..

Page 1 of 1

 


Tired of the Ads? Registered users have 80% less adverts.