- Reaction score
- 1,667
I have finally created my first prototype program in C#. Please report any problems.
The only thing I want to fix is: How do you round a float number?
Only works with integers at the moment.
And I'm thinking of creating some C# solution series in this forum. Not only I can improve my programming skills, but also can give help to those who view these posts. Here's the code in its glorious moments:
Note: To view the improved code, click here.
The only thing I want to fix is: How do you round a float number?
Only works with integers at the moment.
And I'm thinking of creating some C# solution series in this forum. Not only I can improve my programming skills, but also can give help to those who view these posts. Here's the code in its glorious moments:
Note: To view the improved code, click here.
Code:
using System;
namespace Practice
{
public class Lesson_1 //Rounding a number to some places.
{
public void Rounding()
{
int number, Place;
Console.Write("Enter a value needed to be rounded: ");
number = Int32.Parse(Console.ReadLine());
Console.Write("How many places do you want to round [100: hundreds place, 10: tens place, 1: ones place, etc.]: ");
Place = Int32.Parse(Console.ReadLine());
CreatingEnvironment(number, Place);
}
private void CreatingEnvironment(int number, int Place)
{
int Condition = number % Place;
if (Condition >= Convert.ToInt32(Place * 0.5))
{
number = (number + Place) - Condition;
}
else
{
number = number - Condition;
}
Console.WriteLine("{0}", number);
}
}
class MainComponents
{
public void Run()
{
Lesson_1 StartingPoint = new Lesson_1();
StartingPoint.Rounding();
}
static void Main()
{
MainComponents Initializer = new MainComponents();
Initializer.Run();
}
}
}