Computing.Net > Forums > Programming > Need Help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need Help!

Reply to Message Icon

Name: NEED HELP
Date: June 16, 2009 at 08:49:22 Pacific
OS: Windows Vista
Subcategory: C/C++
Comment:

Write a program that converts and prints a user-supplied measurement in inches into:
a. foot (12 inches)
b. yard (36 inches)
c. cemtimeter (2.54/inch)
d. Meter (39.37 inches)


#include <stdio.h>
#include <stdlib.h>

int main()
{
int inch;
int foot;
int yard;
int centimeter;
int meter;
// Compute answer

printf("Enter measurement in inches..."); scanf("%d,&inch");
foot = inch * 12;
yard = inch * 36;
centimeter = inch / 2.54;
meter = inch * 39.37;
printf("%d", &foot);
printf("%d", &yard);
printf("%d", ¢imeter);
printf("%d", &meter);
return 0;
}



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: June 16, 2009 at 12:07:22 Pacific
Reply:

Will your teacher take off points when you turn in someone else's work?


0

Response Number 2
Name: klint
Date: June 16, 2009 at 15:48:24 Pacific
Reply:

At least you've made a start, but you need to look more
carefully at the fine detail.

1. If you are dealing with numbers like 2.54, what type should
your variables be?

2. What do you need to pass to scanf, if it is supposed to set
the value of inch? What are you currently passing to it?

3. What do you need to pass to printf, once you have chosen
the correct data type for your variables?

4. Once you've made the above three corrections, you'll be
able to test your program and you will realise that you've
made repeated errors in all of your calculations. You really
need to think what is happening in your program. You can't
just say to yourself "a foot is twelve inches" and just translate
that into a C statement. You need to work through each tiny
step of what the program does when it executes a statement.

5. Once you've got your program working correctly when it is
given correct input, go for extra marks by getting it to work
correctly with incorrect input. Read your C language manual
about how scanf tells you if it's got the input you expect it to
have. Check the result and if the user enters garbage, flush
the input stream and repeat the question, until the user enters
a proper number.

I hope these clues will help you to complete your task while
still being able to claim that it's your own work.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need Help!

I need help in c plzzz www.computing.net/answers/programming/i-need-help-in-c-plzzz/529.html

Need help programming a 12c508a PIC www.computing.net/answers/programming/need-help-programming-a-12c508a-pic/2510.html

Need help with C programming www.computing.net/answers/programming/need-help-with-c-programming/6970.html