Finding degrees from one number to the next (locker combination)

This is a discussion on Finding degrees from one number to the next (locker combination) within the C++ Programming forums, part of the General Programming Boards category; The lock has a dial with 40 calibration marks numbered 0 to 39. given the initial position of the dial ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    45

    Finding degrees from one number to the next (locker combination)

    The lock has a dial with 40 calibration marks numbered 0 to
    39.

    given the initial position of the dial of the lock and first calbaration I have to find the degrees turned

    I have to:

    turn dial clockwise 2 full turns and stop at the first number of the combination

    Ok that is fine from this I know that one complete turn is 360 since there are 40 calibrations 360/40=9. Therefore there is 9 degrees between each number. I have to make two complete turns which means I add 720 degrees plus how far the calibration is.


    This is what I have so far:


    short num;
    cout << "please enter start position";
    cin >> num

    short numx;
    cout << "please enter first calibraion";
    cin >> numx

    ya I'm kind of lost after that since the degrees change depending on what the numbers are. Ya I could use some help thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You just said it was nine degrees per number. How far apart are any two numbers?

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    45
    Quote Originally Posted by tabstop View Post
    You just said it was nine degrees per number. How far apart are any two numbers?
    So it would just be bigger number - small number. So I use an IF statement right?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    And what would the if statement check?

    (In other words: yes you will probably want an if statement, but let's see whether we're on the same page.)

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    45
    omg I think I got his?


    short num;
    cout << "please enter start position";
    cin >> num

    short numx;
    cout << "please enter first calibraion";
    cin >> numx

    if (num > numx)
    cout << ( (num - numx) * 9 ) + 720 ) << endl;

    else (numx > num)
    cout << ( (numx - num) * 9 + 720 ) << endl;

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by xbusterx View Post
    omg I think I got his?


    short num;
    cout << "please enter start position";
    cin >> num

    short numx;
    cout << "please enter first calibraion";
    cin >> numx

    if (num > numx)
    cout << ( (num - numx) * 9 ) + 720 ) << endl;

    else (numx > num)
    cout << ( (numx - num) * 9 + 720 ) << endl;
    That's what I was afraid you were going to say. The catch in the if(num>numx) case is that the two full turns take you past the number you're trying to get to. (That is, if we start at 10, and our goal is 4, we take two full turns back to 10, and we're six spots away from the four, but six spots the wrong way. So we actually have to go (one full turn - six spots).)

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    45
    short num;
    cout << "please enter start position";
    cin >> num

    short numx;
    cout << "please enter first calibraion";
    cin >> numx

    if (num > numx)
    cout << ( ( 360 - ( (num - numx) * 9 ) ) + 720 ) << endl;

    else (numx > num)
    cout << ( (numx - num) * 9 + 720 ) << endl;

    what good now?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't see anything wrong with it. Of course you should field-test it with your own combination lock (or a pen-and-paper representation of same) to see whether you like what you get.

  9. #9
    Registered User
    Join Date
    Sep 2008
    Posts
    45
    Quote Originally Posted by tabstop View Post
    I don't see anything wrong with it. Of course you should field-test it with your own combination lock (or a pen-and-paper representation of same) to see whether you like what you get.
    so it's good?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursive finding index of the min number in array??
    By kavka3 in forum C Programming
    Replies: 5
    Last Post: 01-18-2009, 07:14 AM
  2. Finding The Hcf Of A Number
    By Saimadhav in forum C++ Programming
    Replies: 5
    Last Post: 10-31-2008, 07:50 AM
  3. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  4. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 10:27 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-26-2001, 12:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21