Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Programming (https://www.askmehelpdesk.com/forumdisplay.php?f=437)
-   -   QBasic help (https://www.askmehelpdesk.com/showthread.php?t=425064)

  • Dec 14, 2009, 03:11 PM
    ladijock
    QBasic help

    How about this one.. can anyone help?

    How about this one?

    You agree to work for a certain employer, but ask to be paid in a peculiar way. After the first day you are paid one penny. On each sucsessive day your pay is doubled. Write a program that determines your pay after 30 days. Your program should display your pay for each day of the 30 day period and the total pay earned after each day.

    Sample Display:

    Day Daily Pay Total Pay

    1 0.01 0.01
    2 0.02 0.03
    3 0.04 0.07
  • Dec 14, 2009, 08:09 PM
    Perito
    Quote:

    Originally Posted by ladijock View Post
    How about this one..can anyone help?

    How about this one?

    You agree to work for a certain employer, but ask to be payed in a peculiar way. After the first day you are paid one penny. On each sucsessive day your pay is doubled. Write a program that determines your pay after 30 days. Your program should display your pay for each day of the 30 day period and the total pay earned after each day.

    Sample Display:

    Day Daily Pay Total Pay

    1 0.01 0.01
    2 0.02 0.03
    3 0.04 0.07

    I'm not sure this is the proper place to put your question. It's really a mathematics question, not a programming one.

    Nonetheless, the first day your pay is 0.01. The second day, 0.02, the third day 0.04. In general, the day's pay is



    where n is the day number. Note that

    So, you perform the summation



    On a computer, in any basic language, this is totally trivial

    Dim sum As Double
    Dim onedays_pay As Double
    Dim i As Integer
    sum = 0

    For i = 1 To 30
    onedays_pay = 0.01 * 2 ^ (i - 1)
    sum = sum + onedays_pay
    Print "On day " & CStr(i) & " the payment is " & CStr(onedays_pay) & ", and the total so far is " & CStr(sum)
    Next i

    Print "The total pay is: " & sum

  • All times are GMT -7. The time now is 10:36 PM.