I recently started to "coding" and I'm really really into the beginning and this is one of my first "projects". It is supposed to be SI converter where you can type value, its unit and the unit you want it to be converted.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program
{
class Program
{
static void Main()
{
decimal one = 1;
decimal two = 0.001m;
decimal three = 0.000001m;
decimal four = 0.000000001m;
decimal five = 0.000000000001m;
decimal answer;
begn: Console.WriteLine("SI converter!\nPlease, enter value: ");
decimal value = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nFactors: \n1.One \n2.Milli(m)\n3.Micro(µ)\n4.Nano(n)\n5.Pico(p)\nEnter factor: ");
decimal factor = int.Parse(Console.ReadLine());
if (factor == 1)
{
factor = one;
}else if (factor == 2)
{
factor = two;
}else if (factor == 3)
{
factor = three;
}else if (factor == 4)
{
factor = four;
}else if (factor == 5)
{
factor = five;
}
Console.WriteLine("\nFactors: \n1.One \n2.Milli(m)\n3.Micro(µ)\n4.Nano(n)\n5.Pico(p)\nEnter the second factor: ");
decimal factor2 = Convert.ToInt32(Console.ReadLine());
if (factor2 == 1)
{
factor2 = one;
answer = value * factor;
Console.WriteLine("The answer is : " + answer);
}
else if (factor2 == 2)
{
factor2 = two;
}
else if (factor2 == 3)
{
factor2 = three;
}
else if (factor2 == 4)
{
factor2 = four;
}
else if (factor2 == 5)
{
factor2 = five;
}
answer = value * factor / factor2;
Console.WriteLine("The answer is : " + answer);
Console.WriteLine("Go again?\nY / N");
char ans =char.Parse(Console.ReadLine());
if (ans == 'y')
{
Console.Clear();
goto begn;
}
if(ans=='n')
{
Console.ReadKey();
}
}
}
}
So the problem is that I don't really like this part and I don't have any idea how to do it :
if (factor == 1)
{
factor = one;
}else if (factor == 2)
{
factor = two;
}else if (factor == 3)
{
factor = three;
}else if (factor == 4)
{
factor = four;
}else if (factor == 5)
{
factor = five;
}
P.S Yes I know its probably really really bad, but its my first try.And if you can give me any tips I'll be really happy :)
Aucun commentaire:
Enregistrer un commentaire