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:
namespace ForLoops
{
class DiskSpace
{
static void Main(string[] args)
{
string sentence= "Input size of {number} file:";
int sum = 0;
int count= int.Parse(Console.ReadLine());
for(int i = 0; i < count; i++)
{
string number=Console.ReadLine();
sum = sum + int.Parse(Console.ReadLine());
}
Console.WriteLine($"Total disk space is {sum} bytes.");
}
}
}
Can anyone please help me to solve it?