For Loop

This is a discussion on For Loop within the C++ Programming forums, part of the General Programming Boards category; I am trying to create a program that allows a user to enter the input amount (ex. .01) Day Input ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    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
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299

    Post

    Not to be rude but I sugesthttp://www.cprogramming.com/tutorial.html
    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
    Posts
    2,934
    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
    Unregistered
    Guest
    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
    Posts
    14
    than again he was asking that the totals have to be doubled, not use a double.

Popular pages Recent additions subscribe to a feed

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