Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 6. Calculate Rectangle Area
- Create a method that calculates and returns the area of a rectangle by given width and height:
- Examples
- Input Output
- 3
- 4 12
- 6
- 2 12
- Hints
- 1. After reading the input
- 2. Create a method, but this time instead of typing "static void" before its name, type "static double" as this will make it to return a value of type double
- 3. Invoke the method in the main and save the return value in a new variable
- using System;
- namespace _06CalculateRectangleArea
- {
- class Program
- {
- static void Main(string[] args)
- {
- var width = double.Parse(Console.ReadLine());
- var height = double.Parse(Console.ReadLine());
- double area = GetRactangleArea(width, height);
- Console.WriteLine(area);
- }
- private static double GetRactangleArea(double width, double height)
- {
- return width * height;
- }
- }
- }
Add Comment
Please, Sign In to add comment