how do u solve this problem

Dr anonymous
Dr anonymous used Ask the Experts™
on
I had this question after viewing Pascal Helo.

i had this script
unit hospital;
interface

implementation
uses crt;
Var
name:string;
typeofroom,tp,tv,nory1,nory2:char;
month, day, year, daysstayed,roomcharge,tpcharge,tvcharge,totalcharge:integer;

const
pc=125;
sc=95;
Wc=75;
Tvc=3.50;
Tpc=1.75;
begin
//prompting
writeln('please enter the patients''s name':44);
readln(name);
writeln('please enter the number of days stayed in the hospital':63);
readln(daysstayed);
writeln('please write the month':31);
readln(month);
writeln('please write the day':29);
readln(day);
writeln('pelase enter the year':30);
readln(year);
writeln('please enter y or n for which typeofroom you used. P for private, S for semi private, and W for ward':57);
readln(typeofroom);
Case typeofroom of 'P':roomcharge:=(pc*daysstayed);
                   's':roomcharge:=(sc*daysstayed);
                   'w':roomcharge:=(wc*daysstayed);
end;
writeln('enter y or n for yes or no if they used the telephone':62);
readln(nory1);
Case nory1 of 'Y':tpcharge:=(tpc*daysstayed);
                 'N':tpcharge:=0;
end;

writeln('enter y or n for yes or no if they used the television':63);
readln(nory2);
Case nory2 of 'Y':tvcharge:=Tvc*daysstayed;
                 'N':tvcharge:=0;
end;
//computing
Totalcharge:=roomcharge+tvcharge+tpcharge;


end.
and the error Error: Incompatible types: got "S80REAL" expected "LONGINT"
2 times
plz help me fix it
thanx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DISCLAIMER: I have ABSOLUTELY NO knowledge of Pascal.

Looks like a simple case of 'Numeric overflow' to me.

Why not just try to change from integer to longint and give it a go!

month, day, year, daysstayed, roomcharge, tpcharge, tvcharge, totalcharge : longint;

Open in new window


I am very well aware of the fact that it is an overkill!

Otherwise declare all your t? variables on a separate line with longint.

Also, are you sure none of the input are having decimal digits?
thanx dude. Ill try that
Geert GOracle dba
Top Expert 2009
Commented:
why do you put :nnn at the end of the writeln ???

https://www.freepascal.org/docs-html/rtl/system/writeln.html

i can't ever remembering seeing that syntax
and i've worked with pascal since 1980

wont work with longint either.
because you are producing a real in some cases with multiplying with these consts
Tvc=3.50;
Tpc=1.75;

change the result vars in those variables to real
tvcharge, ...

btw, pascal is not C++, you don't need () all over
 's': roomcharge := sc * daysstayed;

Open in new window

works without the ( )

and to make it a little more userfriendly ... ignore the case

readln(typeofroom);
typeofroom := uppercase(typeofroom);
Case typeofroom of 'P': // ... roomcharge

Open in new window

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

anyone else with an solution?
Geert GOracle dba
Top Expert 2009
Commented:
not a lot of people monitor the pascal group
i inserted the delphi topic
Geert GOracle dba
Top Expert 2009
Commented:
i have a lot more solutions
but from the post I see, you are learning Delphi ... the good old fashioned way, starting from console

what other solution do you expect ?
Commented:
Simple question man... Tvc and Tpc are Real type. You must change the declaration from Integer to Extended or Real (if old Pascal version) to  the variables involved to multiplications and it will work fine..... I tried it and it was OK. Bye
Geert GOracle dba
Top Expert 2009
Commented:
Wow g f ... didnt i post that already ?

Author

Commented:
thx for contiruting
Geert GOracle dba
Top Expert 2009

Commented:
The first was completely wrong, shouldn't have accepted that.

Author

Commented:
.....
G F

Commented:
To I Read The Famous Manual.... You are right. Sorry
Geert GOracle dba
Top Expert 2009

Commented:
G F did you close this question ?
G F

Commented:
Closed.... Bye

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial