![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
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 ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |