cant figure out whats wrong with this ....

This is a discussion on cant figure out whats wrong with this .... within the C++ Programming forums, part of the General Programming Boards category; > 1 5 > 2 5 > 3 5 Sheesh - what were you expecting??? Surely you must have realised ...

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    > 1 5
    > 2 5
    > 3 5
    Sheesh - what were you expecting???

    Surely you must have realised by now that doing 100 * 0.05 will be 5 whether you do it once or 100 times.

    Code:
    for (int i=1; i < years+1 ; ++i) {
        // does temp depend on the value of i - NO!
        // is temp going to change? - NO
        double temp = forest_rate * uncut_area;
        // what about this one then?
        area_forested = (uncut_area + temp * i);
        cout << i << " " << temp << endl;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  2. #17
    Registered User
    Join Date
    Sep 2001
    Posts
    25

    this is what he expects the program to do......

    the formula ( uncut_area + (forest_rate * uncut_area)
    using the numbers 10000 total area, 100 left uncut, .05 forest rate
    u get 100 + (.05 * 100) which is 105 which equals how much will be left after 1 year
    then 105 + (.05 *100) which is 110.25 is what is left after 2 yrs
    then 110.25 + (.05*110.25) = 115.7625
    an you continue until X number of years has passed ( years is the variable for years)

    after 20 years have passed the answer is supposed to be like........635.33? i dont get it i get 105. then 110, then 115 without the decimals.........
    werid to use a for loop i know.............i figured out i need some way to tell the lloop to take the number from each year an add it to the previous until X number of years has passed.........then output the answer as area_forested........

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    > u get 100 + (.05 * 100) which is 105 which equals how much will be left after 1 year
    > then 105 + (.05 *100) which is 110.25 is what is left after 2 yrs

    Surely you mean
    > then 105 + (.05 *105) which is 110.25 is what is left after 2 yrs

    If so, then like this
    Code:
    for (int i=1; i <= years ; ++i) {
        uncut_area = uncut_area + (forest_rate * uncut_area);
    }
    Then print the value of uncut_area at the end of the loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! I cannot figure out what I'm doing wrong here!
    By chsindian595 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 04:18 AM
  2. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM
  3. please help, i can't figure out what's wrong
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2002, 10:13 PM
  4. What is wrong here?????
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2002, 11:51 AM
  5. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 09:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21