Code is outputting a random integer, changes every time I run it
Heya. I have no idea why it's doing this, I've been tweaking and changing the code for the past hour and it still won't work.
Code:
/* A program to change headings in degrees into bearings */
#include <stdio.h>
int input(); //gets degrees from user
char directionmake(); //calculates direction
int calc(); //calculates degrees to turn after direction
int main()
{
int degrees;
degrees = input();
char direction;
direction = directionmake(degrees);
degrees = calc(degrees);
printf("\n\n%c, \n\n", direction);
printf("%d", degrees);
return 0;
} // program execution
int input()
{
int degrees;
printf("Please state the heading in degrees: ");
scanf("%d", °rees);
return degrees;
}
char directionmake()
{
char direction;
int degrees;
if (degrees < 0)
printf("Bad input");
else if (degrees < 90)
direction = 'N';
else if (degrees < 270)
direction = 'S';
else if (degrees <= 360)
direction = 'N';
return direction;
}
int calc()
{
int degrees;
if (degrees > 90 && degrees < 180)
degrees = degrees - 90;
else if (degrees > 180 && degrees < 270)
degrees = degrees - 180;
else if (degrees > 270 && degrees <180)
degrees = degrees - 270;
return degrees;
}
I feel like there's something blatantly wrong, but I can't see it...
Thanks.