User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 455,964 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,607 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 765 | Replies: 6
Reply
Join Date: Nov 2007
Posts: 6
Reputation: AlexN is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
AlexN AlexN is offline Offline
Newbie Poster

pascal questions

  #1  
Nov 19th, 2007
hey there, does anyone know a way that will allow the user to enter as many positive integers as they want, for each one i need a message to appear that states whether the number is odd or even?

cheers guys
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: pascal questions

  #2  
Nov 20th, 2007
Sounds like you are asked to do something repetitively, so that suggests using a loop. Post some code and we'll help further. (You should be able to do this on your own.)
Reply With Quote  
Join Date: Nov 2007
Posts: 6
Reputation: AlexN is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
AlexN AlexN is offline Offline
Newbie Poster

Re: pascal questions

  #3  
Nov 20th, 2007
program eight;
uses crt;

var
stop : integer;
posinteger : integer;
sum : integer;

begin
sum := 0;
writeln('Enter a positive integer, 0 to quit');
readln(stop);
while stop <> 0 do
begin
posinteger := stop mod 2;
readln;
if posinteger = 0
then
writeln('This number is even')
else

writeln('This number is odd');
readln;
clrscr;
writeln('Enter a positibe integer, 0 to quit');
readln(stop);
end;
end.


done it!
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: pascal questions

  #4  
Nov 20th, 2007
Brilliant.

I'm going to pick. The way your code looks is a tremendous help to understanding.
  1. program eight;
  2. uses crt;
  3.  
  4. var
  5. stop : integer;
  6. posinteger : integer;
  7. sum : integer;
  8.  
  9. begin
  10. sum := 0;
  11. writeln('Enter a positive integer, 0 to quit');
  12. readln(stop);
  13. while stop <> 0 do
  14. begin
  15. posinteger := stop mod 2;
  16. readln;
  17. if posinteger = 0
  18. then writeln('This number is even')
  19. else writeln('This number is odd');
  20.  
  21. sum := sum + stop;
  22.  
  23. writeln( 'Press ENTER to continue' );
  24. readln;
  25.  
  26. clrscr;
  27. writeln('Enter a positive integer, 0 to quit');
  28. readln(stop);
  29. end;
  30.  
  31. writeln( 'The sum of all the numbers you entered is ', sum );
  32. end.
You'll notice I made a couple of minor changes. First, I told the user (who might not be you) what he is expected to do to continue when the program pauses. Also, you had defined a variable "sum" which didn't do anything. I made it do something.

Enjoy!
Last edited by Duoas : Nov 20th, 2007 at 5:52 pm.
Reply With Quote  
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 71
Reputation: Micheus is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
Micheus's Avatar
Micheus Micheus is offline Offline
Junior Poster in Training

Re: pascal questions

  #5  
Nov 25th, 2007
Originally Posted by Duoas View Post
  1. program eight;
  2. uses crt;
  3.  
  4. var
  5. stop : integer;
  6. posinteger : integer;
  7. sum : integer;
  8.  
  9. begin
  10. sum := 0;
  11. writeln('Enter a positive integer, 0 to quit');
  12. readln(stop);
  13. while stop <> 0 do
  14. begin
  15. posinteger := stop mod 2;
  16. readln;
  17. if posinteger = 0
  18. then writeln('This number is even')
  19. else writeln('This number is odd');
  20.  
  21. sum := sum + stop;
  22.  
  23. writeln( 'Press ENTER to continue' );
  24. readln;
  25.  
  26. clrscr;
  27. writeln('Enter a positive integer, 0 to quit');
  28. readln(stop);
  29. end;
  30.  
  31. writeln( 'The sum of all the numbers you entered is ', sum );
  32. end.
Duoas, I think that the readln in the line 16 must be put at line 20 in order to display messages in the lines 18 ou 19 and pause execution, like You put on others code place.

bye
Last edited by Micheus : Nov 25th, 2007 at 2:27 am.
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)

Brazil - Blumenau
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: pascal questions

  #6  
Nov 25th, 2007
Yes, I totally missed that one. I wouldn't just move it, I'd get rid of it completely. The user shouldn't have to press ENTER more than once per answer, and only when asked...

Good eye!
Reply With Quote  
Join Date: Nov 2007
Posts: 6
Reputation: AlexN is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
AlexN AlexN is offline Offline
Newbie Poster

Re: pascal questions

  #7  
Nov 20th, 2007
that rocks! thanks! !
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 9:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC