Problem: Inches to Centimeters

Write a program that reads a number from the console (not necessarily an integer) and converts the number from inches to centimeters. For the purpose it multiplies the inches by 2.54 (because one inch = 2.54 centimeters).

Hints and Guidelines

First, we create a new C# console project in the solution “Simple-Calculations”. We right-click the solution in the Solution Explorer and we choose [Add] -> [New Project…]:

Select [Visual C#] -> [Windows] -> [Console Application] and name it “Inches-to-Centimeters”:

Writing Program Code and Starting the Program

Next, we have to write the program code:

Start the program with [Ctrl+F5]:

Surprise! What is happening? The program doesn't work correctly… Actually, isn't this the previous program?
In Visual Studio the current active project in a solution is marked in semi-black color and it could be changed:

Setting Up a Startup Project

To switch the mode to automatically go to current project, we right-click the main solution and we choose [Set StartUp Projects…]:

A dialog window will open, and you will have to choose [Startup Project] -> [Current Selection]:

And again, we run the program, as usual with [Ctrl+F5]. This time it will start the current open program, which converts inches to centimeters. It looks like it works correctly:

Switching Between Programs

Now let's switch to the previous program (square area). This happens with a double click on the file Program.cs from the previous project “Square-Area” in the panel [Solution Explorer] in Visual Studio:

We press again [Ctrl+F5]. This time the other project should start:

We switch back to the “Inches-to-Centimeters” project and start it with [Ctrl+F5]:

Switching between projects is very easy, isn't it? Just choose the file with the source code of the program, double click it and when it starts, the program from the current file is being executed.

Testing a Program Locally

Let's test with floating point numbers, for example with 2.5:

Depending on the regional settings of the operation system, it is possible instead of using a decimal point (US settings), to use a decimal comma (BG settings).

If the program expects a decimal point and instead a number with a decimal comma you enter the opposite (to enter a decimal point, when a decimal comma is expected), the following error will be produced:

It is recommended to change the settings of your computer to use a decimal point:

Testing in the Judge System

Test your solution here: https://judge.softuni.org/Contests/Practice/Index/504#1.

The solution should be accepted as a completely correct one:

results matching ""

    No results matching ""