954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help! Beginner here

Write a program that prompts the user to input a length expressed in centimeters. The program should then convert the length to inches and output the length expressed in yards, feet, and inches, in that order. For example suppose the input for centimeters is 312. To the nearest inch, 312 centimeters is equal to 123 inches. 123 inches would be this output:
3 yards, 1 foot, and 3 inches.

hey basically i was assigned this problem. I have no problem with coding this, its just that I have no idea how to do the math. I know you have to do something with the modulus and i know the conversions, but i just am having a hard time with designing the algorithm. Any help would be apprecciated! Thanks!

123abc
Newbie Poster
6 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

Post what you have, and people will help out. Otherwise, you may be asking us to do your homework for you, and we've got a rule against that.
Sorry.

As a hint, though: If you're working with ints, division by / gives the answer without remainder. The modulus operator % is the remainder for the same division.
Good luck!

Drowzee
Posting Whiz in Training
245 posts since Jul 2005
Reputation Points: 22
Solved Threads: 5
 
prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

That is definitely NOT me. It may be someone from my same class.

123abc
Newbie Poster
6 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

So basically would I just convert centimeters to yards then get the modulus then convert the modulus by feet and then get the modulus of the feet and convert that modulus to centimeters? Im so confused

123abc
Newbie Poster
6 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

Whoa, whoa, whoa.
This isn't a coding question after all? Okay, okay... Here's what you do.
Break it down into steps, one item at a time.
This makes the problem more managable and you can write functions based on the item list.
For example:
1. Steal underpants
2...
3. PROFITS!

Don't break it down too far, though. Anything that directly relates to a particular step, such as calculating a value and displaying it, can be put in one step.
...
Anyway, this is how I'd approach this program.

Step 1:
Get user input.

Step 2:
Convert input from centimeters to inches.

Step 3:
Convert inches to yards (A yard is input%36), display yards, return value of inches once the full yards are removed.

Step 4:
Convert remaining inches to feet (inches %12). Display feet, return value of inches remaining.

Step 5:
Display inches remaining.

Step 6:
PROFITS!

Drowzee
Posting Whiz in Training
245 posts since Jul 2005
Reputation Points: 22
Solved Threads: 5
 
That is definitely NOT me. It may be someone from my same class.

read that other thread and use the same suggestions. Or do you want somebody to do your work for you?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

drowzeee thank you sooooo much! i've finally gotten my code to work after looking at your suggestions!

And no ancient dragon I was not asking for someone to do the work for me. Like I said I was asking for help regaurding how to approach the problem.

123abc
Newbie Poster
6 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You