A Digital Age Deserves A Digital Leader

Help with C++ Home Work..

Help with C++ Home Work..

Postby lowellabraham » Wed Mar 26, 2008 5:52 am

hey guys,

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

Code: Select all
/*
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: Select all
  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: Select all
  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
Workstation:
CPU: Intel Core 2 Quad Q8200 2.33GHz 1333 MHz FSB
PCB: GA-EP45-UD3R
RAM: 4X1GB DDRII 800MHz
GPU: Nvidia 8400 GS
HDD0: WD 150 GB 10,000 RPM
DISPLAY: 24' Dell UltraSharp Widescreen
Server: Intel Pentium 4 3.40GHz HT 800MHz FSB / 4X1GB DDRII 800MHz / 1X200GB 7200rpm / Windows 2003 Server Standard R2
PRO Level 12
Posts: 585
Joined: Mon Sep 13, 2004 2:54 am
Location: Long Island, New York

Postby NoReflex » Wed Mar 26, 2008 1:05 pm

I think you should print the first state before making the operations in the while loop. You could try something like this :
Code: Select all
   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!
PRO Level 10
User avatar
Posts: 431
Joined: Wed Nov 17, 2004 8:41 pm
Location: Romania

Postby lowellabraham » Wed Mar 26, 2008 1:21 pm

noReflex! thank you soo much dude! you the man! You really help me out here :)

<a href="http://imageshack.us"><img src="http://img407.imageshack.us/img407/5116/06fixeduz4.jpg" border="0" alt="Image Hosted by ImageShack.us"></a><br>
Workstation:
CPU: Intel Core 2 Quad Q8200 2.33GHz 1333 MHz FSB
PCB: GA-EP45-UD3R
RAM: 4X1GB DDRII 800MHz
GPU: Nvidia 8400 GS
HDD0: WD 150 GB 10,000 RPM
DISPLAY: 24' Dell UltraSharp Widescreen
Server: Intel Pentium 4 3.40GHz HT 800MHz FSB / 4X1GB DDRII 800MHz / 1X200GB 7200rpm / Windows 2003 Server Standard R2
PRO Level 12
Posts: 585
Joined: Mon Sep 13, 2004 2:54 am
Location: Long Island, New York

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron
cron