balrougelive

Untitled

Aug 8th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h> // basic input output
  2. //#pragma warning(disable: 4996) ////same use as below. for integer input to disable warnings/issues.
  3. #define _CRT_SECURE_NO_WARNINGS
  4.  
  5. /* Function for abs value */
  6. int doSomeMath(int toDetermine) // declared as type int to return, int is used for input
  7. {
  8. if (toDetermine < 0) // negative integer argument
  9. {
  10. return(toDetermine * -1);
  11. }
  12. else if (toDetermine > 0) // positive integer argument
  13. {
  14. return(toDetermine);
  15. }
  16. else // zero argument
  17. {
  18. return(0);
  19. }
  20. }
  21.  
  22. /* Main */
  23. void main() // declared as type void instead of int. this is okay because this function doesn't need to return a result
  24. {
  25. // variable for input, variable for output
  26. int userInt, userOut;
  27.  
  28. // prompt the user
  29. printf("Please enter an integer: ");
  30.  
  31. // get input from user
  32. scanf("%d", &userInt);
  33.  
  34. // call the function
  35. userOut = doSomeMath(userInt);
  36.  
  37. // print the results
  38. printf("\nThe absolute value of %d is %d\n\n", userInt, userOut);
  39.  
  40. }
Add Comment
Please, Sign In to add comment