Thread: Need help learning MOD for school

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    2

    Need help learning MOD for school

    Hi, I'm knew here and am really struggling in my Intro to C Programming Class and was hoping someone could help me out. My teacher told me that I need to do this:

    Write a program to convert a measurement in centimeters to inches. The numbers of centimeters should
    be read as input. Define int variable for centimeters, inches, and feet. Convert the centimeters to inches,
    then convert the inches to feet and inches (use the % operator). Print the distance in all three units.
    There are 2.54 centimeters in each inch and 12 inches in each foot

    However he isn't very good at explaining things in class. He went over everything very quickly and then left right when the class ended so the majority of the class is completely lost. If anyone could just point me in the right direction of what I need to do that would be more than wonderful. Thank you for reading this long!

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You need to post some code.
    Do you have a book on C?
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Can you do this on paper? You must first solve the problem yourself. If you can't solve it, how can you tell a computer program how to solve it?

    So work through some examples by hand, pick some integer values that are centimeters, then convert them to inches, then feet and inches. Once you figure out the process (what to multiply, divide and mod by), writing the program should be easy.

    A quick note, the % (modulus) operator is nothing more than the "remainder" operator. Remember when you first learned to divide, and your problems were something like 13 ÷ 4 = 3 r1 (4 goes into 13 3 times with a remainder of 1)? The / gives you the 3 part of the answer, and the % gives you the 1. Some examples (note the pattern):
    0 % 3 = 0
    1 % 3 = 1
    2 % 3 = 2
    3 % 3 = 0
    4 % 3 = 1
    5 % 3 = 2
    6 % 3 = 0
    7 % 3 = 1

    EDIT: And as oogabooga pointed out, you need to post your attempt. We can't give away answers for obvious reasons (if you don't think it's obvious, our forum guidelines and homework policy explain it).

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    2
    Quote Originally Posted by anduril462 View Post
    Can you do this on paper? You must first solve the problem yourself. If you can't solve it, how can you tell a computer program how to solve it?

    So work through some examples by hand, pick some integer values that are centimeters, then convert them to inches, then feet and inches. Once you figure out the process (what to multiply, divide and mod by), writing the program should be easy.

    A quick note, the % (modulus) operator is nothing more than the "remainder" operator. Remember when you first learned to divide, and your problems were something like 13 ÷ 4 = 3 r1 (4 goes into 13 3 times with a remainder of 1)? The / gives you the 3 part of the answer, and the % gives you the 1. Some examples (note the pattern):
    0 % 3 = 0
    1 % 3 = 1
    2 % 3 = 2
    3 % 3 = 0
    4 % 3 = 1
    5 % 3 = 2
    6 % 3 = 0
    7 % 3 = 1

    EDIT: And as oogabooga pointed out, you need to post your attempt. We can't give away answers for obvious reasons (if you don't think it's obvious, our forum guidelines and homework policy explain it).
    Sorry, I will continue to work on it for a bit and will post my results if I still can't figure it out. Thank you to both of you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. School
    By Annonymous in forum C Programming
    Replies: 6
    Last Post: 06-14-2011, 11:04 AM
  2. Learning Dos and learning Windows
    By blankstare77 in forum C++ Programming
    Replies: 8
    Last Post: 07-31-2005, 03:48 PM
  3. my school
    By axon in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 05-07-2004, 11:01 PM
  4. school org's
    By adamviper in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-04-2002, 10:58 PM

Tags for this Thread