By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,085 Online
Bytes IT Community
+ Ask a Question
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 <stdio.h>

#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
Share this Question
Share on Google+
14 Replies


P: n/a
"glitter boy" <lo**@nerdshack.com> 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 <stdio.h>
#include <math.h>

#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" <lo**@nerdshack.com> 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

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 <lo**@nerdshack.com> writes
Ok so I have this class for C. I have to write this program for my
instructor,
1: clearly saying it is a home work question.
Pretending is it not does not work here. You are also likely to get
answers that, it you use them, will make it obvious that you did not do
the work yourself.
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
2: clearly state the problem to be solved.
People here are not mind readers. I you can't take the time to properly
explain the problem then no one will take the time to answer.
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
3: clearly state what you are having a problem with. "It doesn't work"
or similar mean you are lazy and have not analysed the problem . Other
people will not either.

AND

here is what I have coded this so far.

#include <stdio.h>

#define FACTOR 2.54

int 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

and here is the page with my instructors algorithm
http://www.gibson.vero-beach.fl.us/c...all/prj02.html
5 any additional information.
If people don't get the same information you have one the problem they
could give you the correct answer to a different problem.
sorry i cant explain this better i am just lost right now


6 Be polite. You are asking for help....
Full marks to Glitter Boy for this model question. This is why he has
got some serious and sensible help.

We should post his question to the FAQ as the model how to ask a
homework question.... though most students don't read it :-(


--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #6

P: n/a
"Chris Hills" <ch***@phaedsys.org> 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 <ch***@phaedsys.org> 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 <lo**@nerdshack.com> writes

[...]
here is what I have coded this so far.

#include <stdio.h>

#define FACTOR 2.54

int 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 <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
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

P: n/a
Chris Hills wrote
(in article <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!


Alternate method that invariably seems to suck a few people into
answering not-so-cleverly-disguised homework problems for them:

"Hey, I have been wondering for a while if it is possible to
"frob the muffler bearing in C while standing on one leg. This
isn't a homework problem, so spare me. It's just pure
coincidence that I ask a question after years of experience that
only a first semester C student would want to be asking and has
no practical purpose in the universe other than amuse teaching
assistants in lower division courses."

Ahhh, great, not a homework problem. Let's all rush to answer
it. *sigh*

I'm routinely disappointed at how transparent some of the
attempts are, yet folks chime in and cough up pages of code in
response. If they lie enough in the intro, nobody ever says
"but post what you have so far first". Just bear in mind that
in a few years, the software you will be downloading onto your
computer will be written by one of these people that steals
everything they do and has no idea why it works, or even if it
does work at all.

--
Randy Howard (2reply remove FOOBAR)

Nov 15 '05 #12

P: n/a
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
....
"Hey, I have been wondering for a while if it is possible to
"frob the muffler bearing in C while standing on one leg. This
isn't a homework problem, so spare me. It's just pure
coincidence that I ask a question after years of experience that
only a first semester C student would want to be asking and has
no practical purpose in the universe other than amuse teaching
assistants in lower division courses."
Very good. Spot on! You've got their number.
Ahhh, great, not a homework problem. Let's all rush to answer
it. *sigh*
You can always reel in a few.
I'm routinely disappointed at how transparent some of the
attempts are, yet folks chime in and cough up pages of code in
response. If they lie enough in the intro, nobody ever says
"but post what you have so far first". Just bear in mind that
in a few years, the software you will be downloading onto your
computer will be written by one of these people that steals
everything they do and has no idea why it works, or even if it
does work at all.


You mean that hasn't happened already?

But yes, it will only get worse.

Nov 15 '05 #13

P: n/a
Kenny McCormack wrote
(in article <dh**********@yin.interaccess.com>):
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
...
"Hey, I have been wondering for a while if it is possible to
"frob the muffler bearing in C while standing on one leg. This
isn't a homework problem, so spare me. It's just pure
coincidence that I ask a question after years of experience that
only a first semester C student would want to be asking and has
no practical purpose in the universe other than amuse teaching
assistants in lower division courses."
Very good. Spot on! You've got their number.


Unfortunately.
Ahhh, great, not a homework problem. Let's all rush to answer
it. *sigh*


You can always reel in a few.


I am sometimes surprised at the names included in that set.
I'm routinely disappointed at how transparent some of the
attempts are, yet folks chime in and cough up pages of code in
response. If they lie enough in the intro, nobody ever says
"but post what you have so far first". Just bear in mind that
in a few years, the software you will be downloading onto your
computer will be written by one of these people that steals
everything they do and has no idea why it works, or even if it
does work at all.


You mean that hasn't happened already?


Excellent point. I'm sure it has happened before, simply
because it has been happening here long enough that some of them
may have accidentally discovered a way to pass the final exams
without consulting Usenet for the answers during the test
itself. There has also been enough time for them to be hired
and make it through one or more development cycles before being
fired for incompetence. Windows seems to be the de facto
indicator of its likelihood. :-)
But yes, it will only get worse.


Why contribute to such an undeserving cause? I suspect it has
more to do with flexing the C muscles in front of an admiring
audience than helping the cheating students.

--
Randy Howard (2reply remove FOOBAR)

Nov 15 '05 #14

P: n/a
"Randy Howard" <ra*********@FOOverizonBAR.net> wrote in message
news:00*****************************@news.verizon. net...
Kenny McCormack wrote
(in article <dh**********@yin.interaccess.com>):
In article <00*****************************@news.verizon.net> ,
Randy Howard <ra*********@FOOverizonBAR.net> wrote:
...
"Hey, I have been wondering for a while if it is possible to
"frob the muffler bearing in C while standing on one leg. This
isn't a homework problem, so spare me. It's just pure
coincidence that I ask a question after years of experience that
only a first semester C student would want to be asking and has
no practical purpose in the universe other than amuse teaching
assistants in lower division courses."
Very good. Spot on! You've got their number.


Unfortunately.
Ahhh, great, not a homework problem. Let's all rush to answer
it. *sigh*


You can always reel in a few.


I am sometimes surprised at the names included in that set.


I am, unfortunately, not surprised. It disappoints to see the greats who
do so, and the general excuse is some version of, "There is no stupid
question."

BTW, you don't frob the muffler bearing, you increase entropy in the
muffler housing component. But that is Off Topic in this forum. Here is
a list of Newsgroups that can not only help you re-adjust the muffler
bearing, but show how to...

I'm routinely disappointed at how transparent some of the
attempts are, yet folks chime in and cough up pages of code in
response. If they lie enough in the intro, nobody ever says
"but post what you have so far first". Just bear in mind that
in a few years, the software you will be downloading onto your
computer will be written by one of these people that steals
everything they do and has no idea why it works, or even if it
does work at all.


You mean that hasn't happened already?


It now Outsourced. I assume these "new lands" that are training up a new
batch of bad programmers who ask first, and program second are also the
first recipients of the software they create. At least, I hope so...
I'm sure it has happened before, simply
because it has been happening here long enough that some of them
may have accidentally discovered a way to pass the final exams
without consulting Usenet for the answers during the test
itself.
Hmmm... I remember putting Calculus formulas on my ruler. I guess now
you text-mail yourself the functions to your Treo 700.

Perhaps there is money to be made here (in writing C code [keeping it
topical, people]) writing Palm and PPC programs for cell phones to
enable cheating. It would certainly generate money while ensuring a
future in job security. (Email me - I program Palm!)

There has also been enough time for them to be hired
and make it through one or more development cycles before being
fired for incompetence. Windows seems to be the de facto
indicator of its likelihood. :-)
But yes, it will only get worse.

Everyone wants to be a System Engineer - it used be Liberal Arts. What
ever happened to Liberal Arts?! And why isn't there a Strict Arts
degree. A bit of a miss there!
Why contribute to such an undeserving cause? I suspect it has
more to do with flexing the C muscles in front of an admiring
audience than helping the cheating students.


And that river in Egypt...

--
Mabden
Nov 15 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.