Last active
August 29, 2015 13:56
-
-
Save JonDouglas/9279624 to your computer and use it in GitHub Desktop.
Rounding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Rounding | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Console.WriteLine(Round(16, 17, 18).ToString()); | |
Console.WriteLine(Round(6, 4, 4).ToString()); | |
} | |
public static int Round(int a, int b, int c) | |
{ | |
int totalSum = 0; | |
totalSum = RoundToTen(a) + RoundToTen(b) + RoundToTen(c); | |
return totalSum; | |
} | |
public static int RoundToTen(int number) | |
{ | |
if (number % 10 >= 5) | |
{ | |
//This will add 5 and then evenly divide the number and then multiply by ten. (This rounds up) | |
return ((number + 5) / 10) * 10; | |
} | |
else | |
{ | |
//This will multiply the evenly divded number by ten. (This rounds down) | |
return (number / 10) * 10; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment