# How do I ensure that the user input in greedy is given to two decimal places?

I have a question about 'Greedy' in pset1. How do I ensure that the input I'm given by the user is in the correct format, namely to two decimal places like 0.00?

## 1 Answer

You're not supposed to get a number from the user that's to two decimal places although you could do that maybe by getting the number as a string then converting it.

• oh, I thought from all the info on the pset that it had to be given as a float. Here's what the pset asks d2o9nyf4hwsci4.cloudfront.net/2014/x/psets/1/pset1/… Sep 30 '14 at 14:57
• It says use 'GetFloat' so the user has to input a float. How do correct a user if they input a figure in cents -nonfloat? Sep 30 '14 at 15:01
• @fuegopazzo yes, you should get a float from the user, but you can't get a float to 2 decimal places using GetFloat. Rather, you should round the float then convert it to the an int to be equal to the number of cents in the amount that the user has provided.
– kzidane
Sep 30 '14 at 15:06
• @fuegopazzo In a "real world" situation the main thing to do would be to clearly communicate to the user that they should give an amount in dollars. There is always the potential for user error. See: GIGO.
– Air
Sep 30 '14 at 15:30
• Here's my code so far, I'm doing it in stages : //ask for change required in format needed printf("How much change do you need? Please give answer in form 0.00: "); float num = GetFloat(); //convert float to int using 'round' then 'cast' from 'float' to 'int' int numtwo = (int) round (num*100); printf("%d \n", numtwo); Oct 1 '14 at 14:11