Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 11th, 2006, 8:12 AM   #1
irish
Programmer
 
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0 irish is an unknown quantity at this point
Calculating error

I've been learning pascal recently and i cant seem to do simple calculations correctly.

Example:

program	calculate;

var
	cost:	real;
	people:	integer;

begin
	Writeln('How many people?');
	Readln(people):
	Writeln('How much per person?');
	Readln(cost);
	Writeln('Total cost: ', people*cost);
	Readln;
end.

Returns a value of 1.800000000Ex01

Any ideas?

Thanks in advance.
irish is offline   Reply With Quote
Old Sep 11th, 2006, 8:45 AM   #2
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
Depending on the input of course there is probably nothing wrong with that output, which has a value of 18 I believe.

I guess where you're having difficulty is in the representation of reals when printed, in this case in exponential or scientific format. Unfortunatly I don't know pascal to suggest a way of changing the output but I'm sure someone here will .
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Sep 19th, 2006, 4:14 AM   #3
irish
Programmer
 
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0 irish is an unknown quantity at this point
Yea found the problem.

Needed to show how many digits:decimal places i wanted to display:

Writeln('Total cost: ', people*cost:6:2);

Thanks anyway Eoin
irish is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
C++ OWL What am I doing wrong Vagabond C++ 7 Mar 24th, 2006 5:31 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
HELP please!!! hamacacolgante C 7 Nov 21st, 2005 5:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC