Skip to content

Instantly share code, notes, and snippets.

@JonDouglas
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonDouglas/9279624 to your computer and use it in GitHub Desktop.
Save JonDouglas/9279624 to your computer and use it in GitHub Desktop.
Rounding
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