How To Convert Millimeter To Any Length In SharpDevelop #1
What Will I Learn?
Hello,in this tutorial i am going to show you guys how to write a simple code to make your calculation easier with SharpDevelop.Basically in this tutorial you will learn how to write a code for converting mm to any length.
- You will learn how to use SharpDevelop to convert mm to any length type.
- You will learn and see how to use math and coding in same spot.
Requirements
- SharpDevelop
- Knowledge of basic c# coding
Difficulty
- Basic
Tutorial Contents
In this tutorial i am going to show you how to use c# (sharpdevelop) to calculate length easily.Let's get it started;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
As usual you need to define libraries because libraries takes codes from the database basically...
namespace Myprogram
In this part we are defining our codes title.You can write whatever you want to.
Class Program
Defining class and naming it as "program"
static void Main(string[] args)
This is a entry point of the code actually.
while (true)
if you using while loop you need to select your condition.
int mm = 0;
int cm = 0;
int dm = 0;
int m = 0;
int dam = 0;
int hm = 0;
int km = 0;
As the start we are defining all length types and equalizing them to zero.All length types are in integer type on purpose.
while (true)
Console.WriteLine("Enter the length in mm type : ");
Console.Write("->");
Again we using while loop and in the second line we asking user to enter any length in mm type,in third line "->" symbol is just for visuality.
try
km = Convert.ToInt32(Console.ReadLine());
break;
**If you are using while loop you can use try and catch loops in it.We are converting kilometer integer to 32byte and making console read the line **
catch (Exception)
Console.WriteLine("Please enter a number...\n\n");
If the user doesn't enter a number this line will catch the problem and warn the user as saying "please enter the number"
mm = km % 10;
km /= 10;
cm = km % 10;
km /= 10;
dm = km % 10;
km /= 10;
m = km % 10;
km /= 10;
dam = km % 10;
km /= 10;
hm = km % 10;
km /= 10;
Arranging length types and as you know for example cm is ten percent of km.That's why we equalize them to ten percent.
Console.WriteLine("\n\n Length : {0} km {1} hm {2} dam {3} m {4} dm {5} cm {6} mm \n\n", km, hm, dam, m, dm, cm, mm);
Again arranging length types from big to small and after adding new lines with \n code defining them
Console.WriteLine("Enter 0 for new try,To Exit Press 1:");
if (Console.ReadLine() == "1")
break;
**Asking user if it wants to keep trying or want to exit.Whatever user enters if clicks to "1" program will stop working. **
Outputs from the code;
Full Code
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
NOTE
Rule says
Contributions must be Formal and Professional
. Your next contributions may be declined if sentences likeGreetings,
Hey guys
is used. Thank you.You can contact us on Discord.
[utopian-moderator]
Fixing it right now,thank you sir!
Hey @rufans, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Hey @milliar I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x