Thread: Please help me! stuck on what to do

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Please help me! stuck on what to do

    i'm stuck on the line for printf("Data: $%4.2f\n", 30+(y-2)*5);.
    you can ignore the lines below this because it is just wrong
    ok, so i'm suppose to create this program that tells the customers how much they pay for their phone. For the data plan, I am suppose to create a line that shows them how much they spend on the data plan. Customers pay 30$ for the first 2.0GB, then they pay 10$ for every GB or fraction thereof. I don't know how to create a line for this! (or I just suck at math ) Anyway, please help me!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    Well, I would store the calculated cost in an int, since there's no fractional dollar amount involved.

    Look up the ceil() function, it's what you want. And cast the return value of ceil
    Code:
     (int)ceil( myfloat )
    Then you can print it using %i specifier followed with ".00"

    You'll also want to multiply the incremental use by 10 if it's $10 per GB and not 5.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    In the future, it would be best if you posted your code here, using code tags.

    What you have for that line so far isn't too bad of a start - although it's not quite correct. It's difficult go "give assistance" without just giving away the solution.

    Code:
    printf("Data: $%4.2f\n", 30+(y-2)*5);
    The "30" is the $30 for the first 2 GB.
    Whatever is left over (y - 2GB) is $10 per GB - so why are you multiplying this value by 5?

    While perfectly legal syntax-wise, I'd suggest taking the formula out of the "printf()" statement and calculating it into another variable first. The reason being: What if someone is only using 1.5 GB? Your formula does not take this scenario into account.

    That's the only line I looked at. If you have further questions about this, or any other logic in this code, then please ask.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help please im stuck
    By ItsMeHere in forum C Programming
    Replies: 7
    Last Post: 06-15-2006, 04:07 AM
  2. Im stuck....
    By dAzed in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 04:50 PM
  3. Stuck
    By goosematt in forum C Programming
    Replies: 1
    Last Post: 11-10-2003, 07:44 AM
  4. stuck ky
    By JaWiB in forum Tech Board
    Replies: 2
    Last Post: 06-15-2003, 08:28 PM
  5. I'm stuck
    By Caliki in forum C Programming
    Replies: 9
    Last Post: 04-23-2003, 05:51 AM