fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. double roundDouble(double numToRound, double multiple)
  6. {
  7. if(multiple == 0)
  8. {
  9. return numToRound;
  10. }
  11.  
  12. return round(numToRound / multiple) * multiple;
  13. }
  14.  
  15. int main() {
  16. cout << roundDouble(110.0, 50.0) << endl;
  17. cout << roundDouble(95.0, 50.0) << endl;
  18. cout << roundDouble(125.0, 50.0) << endl;
  19. cout << roundDouble(750.0, 50.0) << endl;
  20. cout << roundDouble(145.0, 50.0) << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
100
100
150
750
150