Thread: For Loop

  1. #1
    Registered User
    Join Date
    Dec 2001

    Question For Loop

    I am trying to create a program that allows a user to enter the input amount (ex. .01)

    Day Input Total
    1 .01 .01
    2 .02 .03
    3 .04 .07

    The input amount needs to be doubled each day and the total needs to be displayed...

    Any suggestions would be appreciated

  2. #2
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001


    Not to be rude but I sugest
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  3. #3
    Registered User
    Join Date
    Oct 2001
    I guess to input the amount, use either a double or float.

    double amount;
    cin >> amount;

    Or you could have him enter cents and use an integer. Then when you print it out, use the modulus operator (%) to get dollars and cents.

    int amount;
    cin >> amount;
    dollars = amount / 100;
    cents = amount % 100;
    cout << dollars << "." << cents << endl;

    However, the integer may eventually overflow, after you double it numerous times.

  4. #4
    double amount;
    double total = 0.00;
    int days;
    int i;

    enter amount to start with:

    enter number of days to calclulate:

    total = amount;
    cout day 1 amount total;

    for i = 2 i < days, i++
    amount *= 2
    total += amount
    cout day i amount total

  5. #5
    Registered User
    Join Date
    Nov 2001
    than again he was asking that the totals have to be doubled, not use a double.

Popular pages Recent additions subscribe to a feed