Use Of {0} And Comments - C# Programming Exercise

This exercise is great for learning how to interact with the user in C# and perform basic mathematical operations. In this program, the user will be asked to input three numbers, which will then be multiplied together, and the result will be displayed on the screen. Additionally, the program includes a comment at the beginning with the programmer's name, following a good documentation practice in C#.

The instructions for the user are as follows:
1. The program will ask the user to enter three numbers.
2. The three entered numbers will be multiplied together.
3. The result of the multiplication will be displayed on the screen.

This exercise will help you understand how to work with user input using Console.ReadLine(), how to perform multiplications in C#, and how to use comments in your code. Additionally, you will learn how to properly structure your program by following conventions such as including comments with your name at the start of the code.

 Category

First contact with C# Sharp

 Exercise

Use Of {0} And Comments

 Objective

Write a C# program to ask the user for three numbers and display their multiplication. The first line must be a comment with your name and surname. It MUST look as follows:

// Your Name and Surname
Enter the first number to multiply:
12
Enter the second number to multiply:
23
Enter the third number to multiply:
2

 Write Your C# Exercise

using System; // Importing the System namespace to use Console functionalities

// Main class of the programpublic 
class Program
{
    // Main method where the program execution begins
    static void Main()
    {
        // Declaring three variables to store the numbers entered by the user
        double num1, num2, num3;

        // Asking the user to enter the first number and reading the input
        Console.Write("Enter the first number to multiply: ");
        num1 = Convert.ToDouble(Console.ReadLine());

        // Asking the user to enter the second number and reading the input
        Console.Write("Enter the second number to multiply: ");
        num2 = Convert.ToDouble(Console.ReadLine());

        // Asking the user to enter the third number and reading the input
        Console.Write("Enter the third number to multiply: ");
        num3 = Convert.ToDouble(Console.ReadLine());

        // Calculating the result of multiplying the three numbers
        double result = num1 * num2 * num3;

        // Printing the result of the multiplication to the screen using {0}
        Console.WriteLine("The result of multiplying the three numbers is: {0}", result);
    }
}

 Share this C# exercise

 More C# Programming Exercises of First contact with C# Sharp

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Several operations

    This exercise will help you understand how to perform several basic mathematical operations in C#, such as addition, subtraction, multiplication, division, and calculating t...

  •  Multiplication table

    This exercise is perfect for learning how to generate multiplication tables dynamically in C#. In this program, the user enters a number, and the program displays the multip...

  •  Average

    This exercise is a great opportunity to learn how to calculate the average of several numbers in C#. In this program, the user must enter four numbers, and the program will ...

  •  Equivalent operations

    This C# exercise is perfect for learning how to perform mathematical operations with three numbers provided by the user. In this program, the user must enter three numbers: ...

  •  Age

    This C# exercise is perfect for learning how to interact with the user and use input data to personalize the program's output. In this case, the program will ask the user to...

  •  Formats

    This C# exercise teaches you how to handle console output using two different methods: Console.Write and formatting with {0}. In this program, the user will in...