C# Project 1

Test out your knowledge on basic C# programming with a challenging project doing conversions. Covers lessons 1-6 from the beginner series.

Congratulations! You made it to the first project. This is going to test all of the knowledge you have accumulated from lessons 1-6. Refer to them if you need to.
Afterwards you can continue to the next lesson!
Or go back and review the previous lesson.
We also have the source code on GitHub.


/*
* TASK:
*   NOTE: You can assume user input will always be valid
* 
*   Make a program that can do 3 basic conversions:
*       kilometers and miles,
*       celsius and fahrenheit,
*       kilograms and pounds
*   
*   Ask what kind of conversion the user wants to perform:
*       
*       Would you like to convert:
*       1: Distance
*       2: Temperature
*       3: Weight
*       0: Exit
*   
*   The number is what the user will enter.
*   After that selection is made, The user must choose what to convert.
*       
*       Would you like to convert:
*       1: Distance
*       2: Temperature
*       3: Weight
*       0: Exit
*       1
*       
*       1: Kilometers to Miles
*       2: Miles to Kilometers
*       1
*       
*       Enter an amount to convert:
*       5
*       5 Kilometer(s) is 3.10686 Mile(s)
*       
*   After the answer is displayed the program will keep looping untill the user selects 0 to Exit.
*       
*       Would you like to convert:
*       1: Distance
*       2: Temperature
*       3: Weight
*       0: Exit
*       1
*       
*       1: Kilometers to Miles
*       2: Miles to Kilometers
*       1
*       
*       Enter an amount to convert:
*       5
*       5 Kilometer(s) is 3.10686 Mile(s)
*       
*       Would you like to convert:
*       1: Distance
*       2: Temperature
*       3: Weight
*       0: Exit
*       0
*       
*       Goodbye
*       
*   
* 
*   Conversion formulas
*       Kilometer to Mile:      mi = km * 0.62137
*       Mile to Kilometer:      km = mi / 0.62137
*       
*       Celsius to Fahrenheit:  F = (C * 1.8) + 32
*       Fahrenheit to Celsius:  C = (F - 32) / 1.8
*       
*       Kilogram to Pound:      lb = kg * 2.2046
*       Pound to Kilogram:      kg = lb / 2.2046
*/


using System;

namespace Project1
{
    class Conversions
    {
        static void Main(string[] args)
        {

            // Where to start?
            // Step1: Make a while loop that exits when the input is 0              - LESSON 6
                // Step2: Make an if statement that is true when the input is 1     - LESSON 4, LESSON 5
                    // Step3: Make another if that takes 1
                        // Step4: Do the correct conversion                         - LESSON 3

            // TIP: Remember that Console.ReadLine() returns a string
            //      a string "0" IS NOT the same as an Int 0
        }
    }
}

Recommended posts

We have similar articles. Keep reading!

Bubble Sort

Sample source code for implementing bubble sort in C# with an accompanying video explaining how to do it yourself.

C# Lesson 8

Characters, the data type that's just a little less useful than a string.

C# Lesson 7

You're familiar with "while" loops in C#, but but it's time to learn about "for" loops. Let's get loopy in the 7th lesson in our series about learning C#.

C# Lesson 10

Lesson 10 in a our series about learning C# teaches you about working with arrays.

Comments

Log in or sign up to leave a comment.