LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-12-2008, 08:05 PM   #1
Doctorzongo
Member
 
Registered: Mar 2008
Distribution: Fedora 11
Posts: 72

Rep: Reputation: 16
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.
 
Old 04-12-2008, 08:19 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Triangles have area, not volume. That's where you went wrong.

--------------------
Steve Stites
 
Old 04-12-2008, 09:01 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 04-13-2008, 03:28 PM   #4
JMJ_coder
Member
 
Registered: Apr 2006
Distribution: Fedora
Posts: 478

Rep: Reputation: 30
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
 
Old 04-13-2008, 05:11 PM   #5
Doctorzongo
Member
 
Registered: Mar 2008
Distribution: Fedora 11
Posts: 72

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by JMJ_coder View Post
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 ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debugging C++ so called from java program exitsfunnel Programming 3 10-12-2005 03:01 PM
pascal program amer_58 Linux - Newbie 8 08-30-2005 12:56 PM
Debugging Multithreaded Program villie Programming 2 08-17-2004 11:24 AM
wanted : simple debugging task 2mcm Programming 2 08-05-2004 04:26 PM
How to run pascal program in Linux? zWaR Programming 5 02-04-2004 02:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration