Xnyper
September 22nd, 2008, 11:34 PM
I have a homework assignment due next friday. The basic premise of this assignment is passing parameters by reference. Before I pass said parameters, I need to collect some input from the user; this input collection is hardly the point of the program--but it is the point of this post.
before even worrying about the passing of parameters, I wanted to verify that my data collection was going according to planned so I set up a printf to tell me the values of the variables. Much to my dismay, they were all wrong.
for example, if my input is:
1
2
3
then the output of the last printf is:
one: 2.000000
two: -0.000000
three: 32.000001
I went through my code, and replaced all of the %f (for float) with %d (for integer). And suddenly it was working just fine. As far as I can find (in the book and in the notes) there shouldn't be any additional requirements for changing the conversion specifiers, a simple find and replace should effectively change the variable type in question.
I have attached my source, assignment1.c is the working one, with integers. assignment1a.c is the broken one, with floats.
If anyone can tell me why the variable aren't getting stored properly (or possibly why they arent printing properly) in assignment1a.c I would really appreciate it.
Thanks!
before even worrying about the passing of parameters, I wanted to verify that my data collection was going according to planned so I set up a printf to tell me the values of the variables. Much to my dismay, they were all wrong.
for example, if my input is:
1
2
3
then the output of the last printf is:
one: 2.000000
two: -0.000000
three: 32.000001
I went through my code, and replaced all of the %f (for float) with %d (for integer). And suddenly it was working just fine. As far as I can find (in the book and in the notes) there shouldn't be any additional requirements for changing the conversion specifiers, a simple find and replace should effectively change the variable type in question.
I have attached my source, assignment1.c is the working one, with integers. assignment1a.c is the broken one, with floats.
If anyone can tell me why the variable aren't getting stored properly (or possibly why they arent printing properly) in assignment1a.c I would really appreciate it.
Thanks!