LinuxQuestions.org
Help answer threads with 0 replies.
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
 
LinkBack Search this Thread
Old 04-12-2008, 08:05 PM   #1
Doctorzongo
Member
 
Registered: Mar 2008
Distribution: Fedora 11
Posts: 72

Rep: Reputation: 15
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
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Squeeze, Fedora 14
Posts: 7,268

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

--------------------
Steve Stites
 
Old 04-12-2008, 09:01 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,485

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
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
Location: Ohio
Distribution: ArchLinux, NetBSD
Posts: 476

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: 15
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 05:02 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration