fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int getHeading(int val)
  5. {
  6. val %= 360;
  7. return (val < 0)? (val+360) :val;
  8. }
  9.  
  10.  
  11. int main() {
  12. // your code goes here
  13. const int SIZE =6;
  14. int vals[SIZE] = {-360, 360, -361, 361, -1, 1};
  15.  
  16. for(int i = 0; i< SIZE; i++)
  17. {
  18. cout<< vals[i]<< " = " << getHeading(vals[i])<<endl;
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
-360 = 0
360 = 0
-361 = 359
361 = 1
-1 = 359
1 = 1