Tutorial C# Sharp - Learn to program with performing exercises C# Sharp

Tutorial C# Sharp

Learn to program with performing exercises C# Sharp

Float, speed units - Tutorial C# Sharp
Tutorial C# Sharp4,85581245

Float, speed units - Tutorial C# Sharp

Lesson 3:

Basic data types

Exercise 3.10:

Float, speed units


Create a program to ask the user for a distance (in meters) and the time taken (as three numbers: hours, minutes, seconds), and display the speed, in meters per second, kilometers per hour and miles per hour (hint: 1 mile = 1609 meters).

Source Code:

using System;
public class Exercise060
    public static void Main()
        float distance;
        float hour, min, sec;

        float timeSec;
        float mps;
        float kph, mph;

        Console.Write("Enter distance(meters): ");
        distance = Convert.ToSingle(Console.ReadLine());
        Console.Write("Enter timeSec(hour): ");
        hour = Convert.ToSingle(Console.ReadLine());
        Console.Write("Enter timeSec(minutes): ");
        min = Convert.ToSingle(Console.ReadLine());
        Console.Write("Enter timeSec(seconds): ");
        sec = Convert.ToSingle(Console.ReadLine());

        timeSec = (hour * 3600) + (min * 60) + sec;
        mps = distance / timeSec;
        kph = (distance / 1000.0f) / (timeSec / 3600.0f);
        mph = kph / 1.609f;

        Console.WriteLine("Your speed in meters/sec is {0}", mps);
        Console.WriteLine("Your speed in km/h is {0}", kph);
        Console.WriteLine("Your speed in miles/h is {0}", mph);
Exercisey 3.10

Privacy Policy:

Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.


This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.