I'm new

G

glitter boy

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/classes/cop2000/fall/prj02.html

sorry i cant explain this better i am just lost right now
 
A

Alexei A. Frounze

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
 
G

glitter boy

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
 
M

Martin Ambuhl

glitter said:
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;
}
 
A

Alexei A. Frounze

glitter boy said:
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
 
C

Chris Hills

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!

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


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 :-(
 
A

Alexei A. Frounze

Chris Hills said:
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
 
F

Flash Gordon

glitter said:
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.
 
K

Keith Thompson

Chris Hills said:
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!



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.
 
G

glitter boy

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
 
G

glitter boy

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
 
R

Randy Howard

Chris Hills wrote
(in article said:
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.
 
K

Kenny McCormack

Randy Howard said:
"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.
 
R

Randy Howard

Kenny McCormack wrote
(in article said:
Very good. Spot on! You've got their number.
Unfortunately.


You can always reel in a few.

I am sometimes surprised at the names included in that set.
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.
 
M

Mabden

Randy Howard said:
Kenny McCormack wrote


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...


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. :)

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top