CouldnoT Posted June 19, 2020 Share Posted June 19, 2020 (edited) Word Counter This is a small program that allows you to count how many words there are in a text. Here is the script : program counter; uses crt; var text: string; x, c: Integer; procedure count; begin delete (text, x, 1); c:= c+1; end; begin textcolor(white); writeln('Welcome to the word counter'); write('enter the text : '); textcolor(lightblue); readln(text); textcolor(white); c:= 0; repeat begin x:= pos(' ', text); count; end; until(x = 0); If c < 20 then writeln('There is ' ,c, ' words.') Else writeln('There is ' ,c, ' word.'); readkey; end. This counter works by eliminating every time a space from the text and adds +1 in each loop until the number of spaces is zero (position is zero). PS : the position of x should be also integrated in the loop so that the variable gets the new position on each time the loop works. Edited June 20, 2020 by CouldnoT Link to comment Share on other sites More sharing options...
TLG George Posted June 23, 2020 Share Posted June 23, 2020 Topic inactiv. Closed. Link to comment Share on other sites More sharing options...
Recommended Posts