Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
deleted 74 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

So I recently started "coding" and I'm really really into the beginning and this is one of my first "projects". It is supposed to be an SI converter where you can type a value, its unit and the unit to which you want it to be converted.

Can you give me some opinions about the code and how can I can improve? P.S I repeat I'm still beginner in programming so I don't know much.

So I recently started "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.

Can you give me some opinions about the code and how can I improve? P.S I repeat I'm still beginner in programming so I don't know much.

I recently started "coding" and this is one of my first "projects". It is supposed to be an SI converter where you can type a value, its unit and the unit to which you want it to be converted.

Can you give me some opinions about the code and how I can improve?

Rollback to Revision 2
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

I did some things to the code what about now?

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 milli = 0.001m; decimal micro = 0.000001m; decimal nano = 0.000000001m; decimal pico = 0.000000000001m; decimal kilo = 1000; decimal mega = 1000000; decimal giga = 1000000000; decimal tera = 1000000000000; decimal answer; while (true) { 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)\n6.Kilo\n7.Mega\n8.Giga\n9.TeraEnter factor: "); decimal factor = int.Parse(Console.ReadLine()); switch (Convert.ToInt32(factor)) { case 1: factor = one; break; case 2: factor = milli; break; case 3: factor = micro; break; case 4: factor = nano; break; case 5: factor = pico; break; } 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()); switch (Convert.ToInt32(factor2)) { case 1: factor2 = one; answer = factor * value; Console.WriteLine("The answer is "+ answer); break; case 2: factor2 = milli; break; case 3: factor2 = micro; break; case 4: factor2 = nano; break; case 5: factor2 = pico; break; } answer = value * factor / factor2; Console.WriteLine("The answer is : " + answer); Console.WriteLine("Go again?\nY / N"); char ans = char.Parse(Console.ReadLine()); if (ans == 'n') { break; } if (ans == 'y') { Console.Clear(); } } } } } 

I did some things to the code what about now?

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 milli = 0.001m; decimal micro = 0.000001m; decimal nano = 0.000000001m; decimal pico = 0.000000000001m; decimal kilo = 1000; decimal mega = 1000000; decimal giga = 1000000000; decimal tera = 1000000000000; decimal answer; while (true) { 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)\n6.Kilo\n7.Mega\n8.Giga\n9.TeraEnter factor: "); decimal factor = int.Parse(Console.ReadLine()); switch (Convert.ToInt32(factor)) { case 1: factor = one; break; case 2: factor = milli; break; case 3: factor = micro; break; case 4: factor = nano; break; case 5: factor = pico; break; } 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()); switch (Convert.ToInt32(factor2)) { case 1: factor2 = one; answer = factor * value; Console.WriteLine("The answer is "+ answer); break; case 2: factor2 = milli; break; case 3: factor2 = micro; break; case 4: factor2 = nano; break; case 5: factor2 = pico; break; } answer = value * factor / factor2; Console.WriteLine("The answer is : " + answer); Console.WriteLine("Go again?\nY / N"); char ans = char.Parse(Console.ReadLine()); if (ans == 'n') { break; } if (ans == 'y') { Console.Clear(); } } } } } 
added 3508 characters in body
Source Link
BatmanB.
  • 221
  • 2
  • 7
Loading
Tweeted twitter.com/StackCodeReview/status/672146064380731392
edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Loading
Source Link
BatmanB.
  • 221
  • 2
  • 7
Loading