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

1. ## 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. You just said it was nine degrees per number. How far apart are any two numbers? 3. Originally Posted by tabstop 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. 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. 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. Originally Posted by xbusterx 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. 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. 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. Originally Posted by tabstop 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 