Here's the basic algorithm:
1) A password must be entered to use the program.
2) The user must enter a string. Once the string is entered, the program will check for a " / " to terminate the input procedure.
3) The string is analyzed letter by letter using the "read" command. The counter_temp is incremented by one unit. It checks for any spaces entered to distinguish different words within the phrase.
4) The program displays the number of chars contained in the longest word.
Variables:
character: letter entered by the user.
phrase: full string.
counter_temp: Temp storage of phrase. It is incremented every time it reads a character. It is reset to 0 once the user enters a space (marking the beginning of a new word).
counter: It stores the counter_temp quantity once a space is detected. It checks to see if it's larger than counter_temp to later store it as counter_max.
counter_max: It's where the longest word-quantity is stored. It displays the most amount of letters within the longest word.
pass: The program's password.
Here's the code:
procedure Analize_Phrase(var counter, counter_temp, counter_max : byte; character : char; phrase : string);
Begin
If character = ' ' Then
Begin
If (counter > counter_temp) Then
Begin
counter_max := counter;
counter_temp := 0
End
Else
counter := counter_temp;
counter_max := counter;
counter_temp := 0;
End;
If counter_temp <> 0 Then
counter_max := counter_temp;
End;
procedure Main_Program(var counter, counter_temp, counter_max : byte; var phrase : string; var character : char);
Begin
Writeln('Enter the string:');
While (character <> '/') Do
Begin
read(character);
phrase := phrase + character;
inc(counter_temp);
Analize_Phrase(counter, counter_temp, counter_max, character, phrase);
End;
writeln('The longest word entered contains: ',conter_max, ' letters');
readln();
End;
procedure Intro(pass : string);
var counter, counter_temp, counter_max : byte; character : char; phrase : string;
Begin
counter_temp := 0; counter :=0; counter_max := 0;
writeln('Enter the password:');
readln(pass);
If pass = '7540' then
Main_Program(counter, counter_temp, counter_max, character, phrase)
Else
writeln('Wrong password...');
End;
var pass : string;
Begin
Intro(pass);
readln();
End.
The problem is that for some reason it does not read the longest word. It just displays the amount of letters contained in the last word entered. How do I fix it???
Thanks a lot!


Sign In
Create Account


Back to top









