Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Calculation oddity

Pud92Pud92 Member Posts: 4
Right I've been given this to do at school, basically to calculate the size of a sound file - to demonstrate functions.

I'm already solid with all the programming practices in this piece of code, but whenever I try to test it with a standard CD's information I get:

Enter number of samples per second:
44100
Enter number of channels:
2
Enter number of minutes:
74
Enter the bytes per channel:
2
The sample is -371780.63 Kilobytes big

And I just can't see why this is happening! The answer should be 764,859.375

Here's the code:

[code]
program soundsize; { Calculate the size of a sound file - functions }

var
noOfSamples, noOfChannels, noOfMins, bytesPerChannel : integer;
size : real;

function calcSoundSize (noSamples, noChannels, noMins, bytesChannel : integer) : real;
begin
calcSoundSize := noSamples * bytesChannel * noChannels * (noMins * 60) / 1024;
end;

begin
writeln('Enter number of samples per second: ');
readln(noOfSamples);

writeln('Enter number of channels: ');
readln(noOfChannels);

writeln('Enter number of minutes: ');
readln(noOfMins);

writeln('Enter the bytes per channel: ');
readln(bytesPerChannel);

size := calcSoundSize(noOfSamples, noOfChannels, noOfMins, bytesPerChannel);

writeln('The sample is ', size:5:2, ' Kilobytes big');

end.
[/code]

Thanks in advance for any help on this :)

Comments

  • AtexAtex Member Posts: 268

    Try changing the integer type to longint, I don't have a compiler handy to test it but looks to me you have an integer overflow @ those multiplications.
Sign In or Register to comment.