425,910 Members | 1,085 Online
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

# I'm new

 P: n/a Ok so I have this class for C. I have to write this program for my instructor, where he has already posted the softcopy and algorithm. But my question is I have to convert meters to feet and in this I have to output not only the feet but also the inches now I think I have coded the feet calculation properly but. I don't know how to send the remainder to inches and than recalculate it and display that calculation here is what I have coded this so far. #include #define FACTOR 2.54 int main (void) { float HM /*hight in meters*/ float INCHES /*hight in inches (later adjust to just inches of height)*/ float FEET /*whole feet portion of height*/ /*title and credits*/ printf ("Height Converting Program\n"); printf ("Designed by Randolph Gibson - 15 january 2001\n"); printf ("Coded by Rome Baker - September 2005\n\n"); /*explanation*/ printf ("This program will convert a person?s height from meters\n"); printf ("into feet and inches (rounded to the nearest inch) and \n"); printf ("display the result on the screen. The height must be\n"); printf ("entered in metric units and contain decimal portions.\n"); printf ("The andwer will be displayed in whole feet and inches.\n\n"); /*requesting HM*/ printf ("Enter the person?s height in meters:"); scanf ("%f", &HM); /*claculate and store numbers*/ INCHES = HM * 100 / FACTOR; FEET = INCHES / 12; /*display answers*/ printf ("\nThe height is equivilant to %.0f feet and ") return (0); } and here is the page with my instructors algorithm http://www.gibson.vero-beach.fl.us/c...all/prj02.html sorry i cant explain this better i am just lost right now Nov 15 '05 #1
14 Replies

 P: n/a "glitter boy" wrote in message news:11**********************@g43g2000cwa.googlegr oups.com... You must write the code yourself. If the conversion and rounding aren't clear, here's example: h_in_meters = 1.8; h_in_inches = h_in_meters * 100/*cm per meter*/ / 2.54 /*cm per inch */; /* < 71 -- round to nearest ((int)(0.5+being_rounded)) when printing as D1 */ h_in_foots = h_in_inches / 12; /* < 6 -- round when printing, if printing as D2 round down (floor()) */ now to get D3: h_in_inches2 = h_in_inches - floor(h_in_foots) * 12; /* < 11 -- round to nearest (as pointed above) when printing as D3 */ HTH, Alex Nov 15 '05 #2

 P: n/a Thank you for your help. I have finished codeing and my code will complie with no errors. But when I run the program I get a -1 error Any sugestions? ~Rome Nov 15 '05 #3

 P: n/a glitter boy wrote: Ok so I have this class for C. I have to write this program for my instructor, where he has already posted the softcopy and algorithm. But my question is I have to convert meters to feet and in this I have to output not only the feet but also the inches now I think I have coded the feet calculation properly but. I don't know how to send the remainder to inches and than recalculate it and display that calculation here is what I have coded this so far. [...] float HM /*hight in meters*/ float INCHES /*hight in inches (later adjust to just inches of height)*/ float FEET /*whole feet portion of height*/ leaving off those semicolons will kill you. It is conventional to use all uppercase only in naming macros. Try seeing if you can tell what's happening here: #include #include #define FACTOR 2.54 int main(void) { double height_in_meters; double inch_portion_of_height; double foot_portion_of_height; printf("Height Convertion Program\n" "Designed by Randolph Gibson - 15 january 2001\n" "Coded by Rome Baker - September 2005\n\n" "This program will convert a person's height from meters\n" "into feet and inches (rounded to the nearest inch) and \n" "display the result on the screen. The height must be\n" "entered in metric units and contain decimal portions.\n" "The answer will be displayed in whole feet and " "inches.\n\n"); do { printf("Enter the person's height in meters: "); fflush(stdout); scanf("%lf", &height_in_meters); if (height_in_meters <= 0) printf("We deal only in people with heights > 0.\n"); } while (height_in_meters <= 0); inch_portion_of_height = height_in_meters * 100 / FACTOR; foot_portion_of_height = floor(inch_portion_of_height / 12); inch_portion_of_height -= 12 * foot_portion_of_height; printf("\nThe height is equivilant to %.0f'%.0f\".\n", foot_portion_of_height, inch_portion_of_height); return 0; } Nov 15 '05 #4

 P: n/a "glitter boy" wrote in message news:11**********************@g49g2000cwa.googlegr oups.com... Thank you for your help. I have finished codeing and my code will complie with no errors. But when I run the program I get a -1 error Where? Any sugestions? What did you return in main()? Post your code. Alex Nov 15 '05 #5

 P: n/a "Chris Hills" wrote in message news:YM**************@phaedsys.demon.co.uk... Hi to any students. THIS is the model of how to ask for help with homework... Ask your questions this way and you will get help! .... I second that! And it should not apply to students only, there're guys who aren't students (yet or already) but they do things the wrong way too. :) The root of the problem is the blatant consumerism and egoism: people want to get but not give and often times they fail even to tell what they want and they fail to be polite enough to get the help they're asking for. Instead of helping themselves and others to get the problem solved they add more problems by such a behavior. If they only attempted to put themselves on the side of the answerers/helpers, they'd start seeing where they're wrong. Alex Nov 15 '05 #7

 P: n/a glitter boy wrote: Thank you for your help. I have finished codeing and my code will complie with no errors. But when I run the program I get a -1 error Any sugestions? Yes, post your code so we can actually see what you have done rather than expecting us to use divination. Also, tell us *exactly* what input you fed it, *exactly* what output you got, and what you actually expected. Finally, please use copy and paste rather than retyping so we don't have to try and guess what errors are typos and what are the actual errors in your program. -- Flash Gordon Living in interesting times. Although my email address says spam, it is real and I read it. Nov 15 '05 #8

 P: n/a Chris Hills writes: Hi to any students. THIS is the model of how to ask for help with homework... Ask your questions this way and you will get help! In article <11**********************@g43g2000cwa.googlegroups .com>, glitter boy writes [...] here is what I have coded this so far.#include #define FACTOR 2.54int main (void) 4: Post your attempt at solving the problem. No one is going to write code for you but if you have a go they will point you in the write direction and suggest improvements or point out the obvious errors Agreed with one minor caveat: The posted code doesn't compile. If you're having trouble with the syntax of the language, posting non-compiling code is ok. If you're having trouble with semantics, or with an algorithm, take the time to make the code syntactically correct before posting it, even if it doesn't work. Run it through the compiler, fix what it complains about, and iterate until the compiler is happy. It makes it easier for us to help you. -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. Nov 15 '05 #9

 P: n/a Thank you all for you help with this. I have finished codeing and the program runs great. Thank you all again I do truly appreciate all the help. ~Rome Nov 15 '05 #10

 P: n/a Thank you all for you help with this. I have finished codeing and the program runs great. Thank you all again I do truly appreciate all the help. ~Rome Nov 15 '05 #11