Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Need help with Pascal Project for school...

pascal school project else statement

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 patriotaki

patriotaki

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 02 November 2013 - 05:48 AM

Hello I need some help with pascal for school. The problem is :

 

Read a number,check if it is 3 digit number.

If it ends with "2" or "4" print "Cat A"

If it ends with "1" or "3" print "Cat B"

If it ends with ">5" and "<8" print "Cat C"

If it ends with "0" or "9" print "Cat D"

 

Heres my code : But i get error in the else statement .

I got a test on Monday and i need to know how the if/else statement work in pascal :)

program x;
var
abc,c:Integer;
begin
writeln('give abc'); readln(abc);
if (abc>99) and (abc<999) then
	c:=(abc mod 10);
	if (c=2) or (c=4) then
		writeln('Cat A,you must pay..');
	if  (c=1) or (c=3) then
		writeln('Cat B');
	if (c>5) and (c<8) then
		writeln('Cat C');
	if (c=0) or (c=9) then
		writeln('Cat D');
else
	writeln('3 digits');
end. 

PS: Im using PAME PASCAL (http://samartzidis.g...b.io/education/) its a greek one but it also has english language

 

Thanks.

Attached Thumbnails

  • Capture.PNG

Edited by patriotaki, 02 November 2013 - 05:49 AM.


#2 patriotaki

patriotaki

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 02 November 2013 - 10:08 AM

removing the semicolon before the else statement fixed it!



#3 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts

Posted 03 November 2013 - 02:13 AM

Glad that you could solve it yourself. However I would like to suggest something to improve your codes.

 

I understand that your problem was an exercise. But if you are allowed to, you can use case for checking the content of variable c. It will make your code easier to read and maintain. Case also supports else.

 

Additional note:

  • You did not do anything when the input number's length was not 3. I think this should be the place for your first else.

 

Cheers!


Edited by Luthfi, 03 November 2013 - 02:16 AM.


#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 04 November 2013 - 05:58 AM

I would suggest using "else if" instead of "if" for all but the first if statement, otherwise that final else could correspond to an earlier if and you'll get two messages.

 

Alternately, wrap the whole batch of 4-digit logic in Begin-End.


Edited by WingedPanther, 04 November 2013 - 05:59 AM.

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 patriotaki

patriotaki

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 04 November 2013 - 10:15 AM

hey thanks for your answers :) i Will look  at it and make some research first :)

 

Thanks  :thumbup1:






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download