View Single Post
Old 01-14-2013, 11:10 PM   PM User | #2
negative zero
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
negative zero is an unknown quantity at this point
I can tell just by reading that my implementation won't compile this. My implementation has no <cs50.h>. In addition, I've never seen a built-in GetFloat().

I have reason to believe that cs50.h is a project file. If this is the case, it doesn't belong between <these brackets> but instead between "these quotation marks".

I have reason to believe that GetInt() is declared and defined in cs50.h. Code shouldn't be defined in .h (header) files, but in .c files. Furthermore, "GetFloat()" seems a horrible Java-esque practise. The reason it's horrible in C is that C has no exceptions. By masking the return value of scanf, you are making error handling extremely difficult. I suggest studying this scanf manual carefully before answering the following questions:
1. How would you describe the value that scanf returns on match failure?
2. How would you describe the value that scanf returns when stdin is EOF-marked, or some other error occurs?
3. What would be the only successful return value of a scanf call that is expected to write to 4 items?

Once you've studied that manual carefully, you shouldn't need to mask it behind GetFloat.
negative zero is offline   Reply With Quote