Hey , im trying to really get a feel for Programming. I realllly enjoy it,i've been looking for a programming community to get familiar with , so as to not become detered from repeditive coding from solving porblem issues.I would be grateful to any1 who can help. Im taking a cs50 course online, one of the criteria is to convert change into coin amounts (IE quarter, nickel, dime, pennies). Im having issues in c proggramming, when using a "float" i canno't display the change in the hndredth's place? promise your not wasting your time, im putting a real effort into this , just i don't knw where else oto turn. thanks. My code so far:#include<stdio.h> #include<cs50.h> #include<math.h>intmain (void) { float x,i;x = .25; do { printf("How much change is owed? \n") ;scanf("%f", &i); } while (i < .01); { i = (i) / (x); printf("%f \n",i);}

}

-- Mon Sep 24, 2012 1:26 pm --

i just changed the the div to fmod i = fmod (i, x); printf("%.11f \n",i); ,i get an out put number : 0.15999999642 . i need it to round to the hundreths place?

wilde1 wrote:Hey , im trying to really get a feel for Programming. I realllly enjoy it,i've been looking for a programming community to get familiar with , so as to not become detered from repeditive coding from solving porblem issues.I would be grateful to any1 who can help. Im taking a cs50 course online, one of the criteria is to convert change into coin amounts (IE quarter, nickel, dime, pennies). Im having issues in c proggramming, when using a "float" i canno't display the change in the hndredth's place? promise your not wasting your time, im putting a real effort into this , just i don't knw where else oto turn. thanks. My code so far:#include<stdio.h> #include<cs50.h> #include<math.h>intmain (void) { float x,i;x = .25; do { printf("How much change is owed? \n") ;scanf("%f", &i); } while (i < .01); { i = (i) / (x); printf("%f \n",i);}

}

-- Mon Sep 24, 2012 1:26 pm --

i just changed the the div to fmod i = fmod (i, x); printf("%.11f \n",i); ,i get an out put number : 0.15999999642 . i need it to round to the hundreths place?

Congrats, this is an easy fix for you! If you want to shorten the length of the float you're printing, simple put "-the minimum number of characters to be printed-%f". I took you program and copied it, line for line, (though I did reorganize it) and just added what I told you above, here's what it looks like:

Some sidenotes:1. You might want to check out this site: http://www.cplusplus.com . It has great online documentation of both C, and C++ functions2. You should use code tags surrounding your code when posting code on the forums, it really makes it more readable for us3. You should organize your code so that others know what's going on immediately, without having to hunt for clues4. ALWAYS USE RETURN 0; !5. You don't need to do "int main(void)", int main() works just fine6. Welcome to HTS!

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook