Advertisement
Guest User

Untitled

a guest
Jan 18th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. More info--
  3. This is for an assignment in which I must use the floor() function to round a variable "number" to
  4. various accuracies. When I try to compile I get:
  5.  
  6. Error: Conflicting types of (every function starting with round)
  7. Previous declaration of (function starting with round) was here
  8. Error: Too few arguments to function (starting with round)
  9.  
  10. Any help would be greatly appreciated! Thank you in advance.
  11. **/
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <math.h>
  16.  
  17.  
  18. float number=0, roundedInteger=0, roundedTenth=0, roundedHundredth=0, roundedThousandth=0; //global variables
  19. float roundToInteger(float roundedInteger), roundToTenth(float roundedTenth), roundToHundredth(float roundedHundredth), roundToThousandth(float roundedThousandth); //function protos
  20.  
  21. int main()
  22. {
  23.     printf("This program takes a decimal and rounds it to different levels.\nEnter the number to be rounded.");
  24.     scanf("%f", &number);
  25.     printf("Rounded to nearest integer: %f", roundToInteger()); // calls the function to find rounded number
  26.     printf("Rounded to nearest tenth: %f", roundToTenth()); // calls the function to find rounded number
  27.     printf("Rounded to nearest hundredth: %f", roundToHundredth()); // calls the function to find rounded number
  28.     printf("Rounded to nearest thousandth: %f", roundToThousandth()); // calls the function to find rounded number
  29.     return 0;
  30. }
  31.  
  32. roundToInteger()
  33. {
  34.     roundedInteger=(floor(number)/1);
  35.     return (roundedInteger);
  36. }
  37.  
  38. roundToTenth()
  39. {
  40.     roundedTenth=(floor(number)/10);
  41.     return (roundedTenth);
  42. }
  43.  
  44.  
  45. roundToHundredth()
  46. {
  47.     roundedHundredth=(floor(number)/100);
  48.     return (roundedHundredth);
  49. }
  50.  
  51.  
  52. roundToThousandth()
  53. {
  54.     roundedThousandth=(floor(number)/1000);
  55.     return (roundedThousandth);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement