Hello, I’m working on this task:
Your next task is to calculate the total amount of space that files occupy on a hard drive.
First, read an integer from the console that represents the total number of files. Then, read a series of numbers that represent the size of each file. Write a program that asks the user to input size of each of these files using the phrase: “Input size of {number} file:”. number represents the order of the files, starting with 1 and incrementing for each file. Finally, find the sum of all of the file sizes and output this result in the following format: “Total disk space is {sum} bytes.” For example:
>3
Input size of 1 file:
>2
Input size of 2 file:
>7
Input size of 3 file:
>12
Total disk space is 21 bytes.
Here is my code:
using System;
namespace ForLoops
{
class DiskSpace
{
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 0; i < count; i++)
{
int number = 1 + i;
Console.WriteLine($"Input size of {number} file");
sum = sum + int.Parse(Console.ReadLine());
}
Console.WriteLine($"Total disk space is {sum} bytes." );
}
}
}
Can anyone please help me to solve it?