LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help with debugging Pascal program wanted. (https://www.linuxquestions.org/questions/programming-9/help-with-debugging-pascal-program-wanted-634959/)

Doctorzongo 04-12-2008 08:05 PM

Help with debugging Pascal program wanted.
 
Hello everyone. I wrote a Pascal program to calculate the volume of triangles (I was bored ...) but it appears to be buggy.
If someone could point me to where it went wrong that would be great, thanks.
Code:

program tv;

var
        triangle, triangleside, trianglebottom, volume, height, af: integer;
        ex, un: string;

begin
        Writeln('Hello. This program will calculate Triangular Volumes.');
        Writeln('');
        Writeln('');
        Writeln('Please input the unit of measurement: ');
        Readln(un);
        Writeln('');
        Writeln('Please input the size of your triangle''s side in ', un,': ');
        Readln(triangleside);
        Writeln('');
        Writeln('Please input the size of your triangle''s bottom in ', un,': ');
        Readln(trianglebottom);
        af := triangleside + trianglebottom;
        triangle := af DIV 2;
        Writeln('');
        Writeln('The area of your triangle is: ', triangle, '', un, ' squared.');
        Writeln('Please input the height of your object: ');
        Readln(height);
        Writeln('');
        volume := af * height;
        Writeln('The volume of your triangle is: ', volume, '', un, 'to the power of 3.');
        Writeln('So long, and thanks for all the numbers.');
        Writeln('Press ENTER to exit.');
        Readln(ex);
end.


jailbait 04-12-2008 08:19 PM

Triangles have area, not volume. That's where you went wrong. :D

--------------------
Steve Stites

jlinkels 04-12-2008 09:01 PM

How can you tell it is buggy?

I assum you know you calculate some kind of wedge shape. not a tetraeder or whatever that is called in English.

jlinkels

JMJ_coder 04-13-2008 03:28 PM

Hello,

For starters, your basic formula for calculating the area is wrong.
Code:

af := triangleside + trianglebottom;
        triangle := af DIV 2;

The formula for the area of a triangle is: 1/2 (base * height).
You need to multiply triangle height by triangle bottom. Triangle side would only work in a right angle triangle.

Area Formulas

Doctorzongo 04-13-2008 05:11 PM

Quote:

Originally Posted by JMJ_coder (Post 3120157)
Hello,

For starters, your basic formula for calculating the area is wrong.
Code:

af := triangleside + trianglebottom;
        triangle := af DIV 2;

The formula for the area of a triangle is: 1/2 (base * height).
You need to multiply triangle height by triangle bottom. Triangle side would only work in a right angle triangle.

Area Formulas

DOH! Sorry for the trouble ...


All times are GMT -5. The time now is 03:31 PM.