How To Convert Millimeter To Any Length In SharpDevelop #1

in #utopian-io7 years ago (edited)

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;

1.png

As usual you need to define libraries because libraries takes codes from the database basically...

namespace Myprogram

2.png

In this part we are defining our codes title.You can write whatever you want to.

Class Program

3.png

Defining class and naming it as "program"

static void Main(string[] args)

This is a entry point of the code actually.

while (true)

4.png

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;

5.png

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("->");

6.png

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;

7.png

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);

8.png

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;

9.png

**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;

10.png

Full Code

11.png



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

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 like Greetings, 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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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