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)
{
Console.WriteLine("Input size of {number} file:");
int numberOfFiles = int.Parse(Console.ReadLine());
int totalSize = 0;
for (int i = 1; i < numberOfFiles; i++)
{
Console.WriteLine($"Input size of file {i}");
int size = int.Parse(Console.ReadLine());
totalSize += size;
}
Console.WriteLine($"Total disk space is {totalSize} bytes:");
The ouput that the console gives me is:
“Input size of file 1
Input size of file 2
Total disk space is 9 bytes:”
And it gives me an error for:
" Errors from testing your code:
4
4
8
12
16"
Can anyone please help me to solve it?