• 02-04-2013
Joshua Rhee
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 :D
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!
• 02-04-2013
Tclausex
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.
• 02-04-2013
Matticus
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.