Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

Calculating the volume of water needed to fill a fish tank.

★★☆

Supplements are often added to an aquarium to replace minerals, fertilisers or for medication. Knowing the correct volume of water in the tank is important so you know how much to dose.

Fish tank volume

Make

Write a program that calculates the volume of a fish tank in litres and imperial gallons from the length, width and height in centimeters.

Success Criteria

Remember to add a comment before a subprogram to explain its purpose.

Complete the subprogram called volume so that:

  1. It returns the volume of water calculated as (length * width * height) / 1000.

Complete the subprogram called litres_to_gallons so that:

  1. It returns gallons as litres / 4.546.

Complete the main program so that:

  1. It allows the user to input the length, width and height of the fish tank in centimeters as integers.
  2. It calculates the litres and gallons using the subprograms.

Typical inputs and outputs from the program would be:

Enter the length of the tank in cm:
60
Enter the width of the tank in cm:
30
Enter the height of the tank in cm:
24
A 60 x 30 x 24 cm tank is 43.2 litres and 9.50285965684118 imperial gallons.
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// Fish tank volume program

using System;

class Submission
{
---
    // -------------------------
    // Subprograms
    // -------------------------
    // Calculate the volume of the fish tank
    static double volume(int length, int width, int height)
    {
---
        return (length * width * height) / 1000.0;
---
    }
---

    // Convert litres to gallons
    static double litres_to_gallons(double litres)
    {
---
        return litres / 4.546;
---
    }
---

    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        Console.WriteLine("Enter the length of the tank in cm:");
        int length = Convert.ToInt32(Console.ReadLine());
---
        Console.WriteLine("Enter the width of the tank in cm:");
        int width = Convert.ToInt32(Console.ReadLine());
---
        Console.WriteLine("Enter the height of the tank in cm:");
        int height = Convert.ToInt32(Console.ReadLine());
---
        double litres = volume(length, width, height);
---
        double gallons = litres_to_gallons(litres);
---
        Console.WriteLine("A " + length + " x " + width + " x " + height + " cm tank is " + litres + " litres and " + gallons + " imperial gallons.");
---
    }
---
}