Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Invisible tech Budjanovci

Pascal, help with program

Recommended Posts

Posted · Original PosterOP

im practicing this for school and its not working

my homework is to make a code that counts number of words in sentence but there are 2 spaces or more between words so  i can count number of spaces+1  

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var s:string;
  br,i,a:integer;

begin
readln(s);
br:=0;
for i:=1 to length(s) do
if s=' ' then
begin
while pos(' ',s)+1=' ' do                  < shows ereor there
begin
a:=0;
a:=pos(' ',s)+1;
delete(s,a,1);
end;
br:=br+1;
end;
br:=br+1;
writeln(br);
readln;

  { TODO -oUser -cConsole Main : Insert code here }
end.
 

Link to post
Share on other sites
3 minutes ago, Invisible tech Budjanovci said:

im new juststarted learnig so i dont know much, in school we complie it in delphi

Yeah, they teach Pascal in schools here, too. Don´t know why they don´t teach the kids something like PHP.

Link to post
Share on other sites
2 minutes ago, brunostejskal said:

Yeah, they teach Pascal in schools here, too. Don´t know why they don´t teach the kids something like PHP.

Nothing wrong with Pascal. It's a solid language to learn the basics of coding and it still has a number of applications (science, along with FORTRAN, for example) its used in


So rise up, all ye lost ones, as one, we'll claw the clouds

Link to post
Share on other sites
1 minute ago, Radium_Angel said:

Nothing wrong with Pascal. It's a solid language to learn the basics of coding and it still has a number of applications (science, along with FORTRAN, for example) its used in

It's fine i agree. But the syntax is a bit hard to grasp for new developers. I'm not that surprised it still taught. Around here some schools still teach delphi/pascal for basic classes.

Link to post
Share on other sites
2 hours ago, brunostejskal said:

obsolete

If it does what you need it to do, then it's not obsolete.

Several of our million dollar (plus) scientific instruments in our lab run programs written in Pascal.

And god help me, we have one done in COBOL...


So rise up, all ye lost ones, as one, we'll claw the clouds

Link to post
Share on other sites
4 hours ago, brunostejskal said:

Is this the 1980s ?

How Blaise of you. That was Wirth alot.


Teacher: Does anyone have a thin ruler?

Students: No.

Teacher: Ok. Does anyone have a nail file.

Students: Why do you need a nail file?
Teacher: I have a staple I need to remove.

Student: Oh. I have a staple remover...

 

People don't want power drills, they want holes.

Link to post
Share on other sites
program Project1;

{$APPTYPE CONSOLE}

uses
 SysUtils;
 var s:string;
 i:integer;
 l:integer;
 counter: integer;
 words: integer;
 c: char;

begin
write('Your text:');
readln(s);
words := 0;
counter := 0;
l := length(s);
if l<1 then begin
  writeln('Not enough characters in the text! Press ENTER to quit.');
  readln;
  exit;
end;
for i := 1 to l do begin
    c := s[i]; { get character at offset i }
    if (c=' ') then begin  {space character}
      if counter>0 then begin  {was there at least a character not space before?}
        writeln('Adding word with ',counter,' characters.');
        words := words + 1;   { yes, increase word count, reset char counter}
        counter := 0;
      end;
    end;
    if (c<>' ') then begin           { not a space, part of word}
         counter := counter+1;
    end;
 end; { end of for loop }
{ reached end of string, if there was more than 1 char not space, add word}
{ you could avoid this by adding a space character to end of string before the
  for loop, IF you know the string will always be less than 255 characters
}
if (counter>0) then begin
   writeln('Adding word with ',counter,' characters.');
   words := words +1;
end;

writeln('Number of words: ',words);
readln;

end.  

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×