?
Solved

error in expression

Posted on 2000-04-11
5
Medium Priority
?
224 Views
Last Modified: 2010-04-16
It's giving me an error in expression on this line: if ord(str[i]) > = 'A'

var
    state: string;
    capital : string;
    Statefile: text;
    states: text;
    tries: integer;
    guess: string;
    correct_guess: integer;
    correct_state: string;


procedure GETDATA (var localStatefile: text;
                   var localstate: string;
                   var localcapital: string);
   begin
      readln (localStatefile, localstate);
      readln (localStatefile, localcapital);
   end; {GETDATA}


procedure GUESS_CAPITAL (var tries: integer;
                         guess: string;
                         var localcorrect_guess: integer);

   begin{GUESS_CAPITAL}
      tries := 0;
     repeat
       tries := tries + 1;
       write ('Give capital of ', state, ' ' );
       readln (guess);
     until (guess = capital) or (tries = 4);
      if guess = capital then
         begin
           writeln ('Nice work. You got it on try ', tries);
           inc(localcorrect_guess);
             if tries = 1 then
                writeln (states, guess);
         end
      else
          begin{until}
           writeln ('You did not get it in 4 tries or less');
           writeln ('The correct answer is ', capital);

     end;{until}
  end; {GUESS_CAPITAL}

procedure GUESSES (localcorrect_guess: integer);
   begin
     writeln ('You have guessed ' ,localcorrect_guess, ' states in 4 or fewer tries ');
   end;{GUESSES}


procedure Tolower (var str: string);
 var i: integer;
   begin
      for i:= 1 to length (str) do
         if ord(str[i]) > = 'A' and ord(str[i]) < = 'Z' then
             str[i] = chr(ord(str[i] - 'A' + 'a'))
   end; {tolower}


begin {main}
     assign (Statefile, 'A:\state2.dat');
     reset (Statefile);
     assign (states, 'A:\state3.dat');
     rewrite (states);
     correct_guess:= 0;
     while not seekeof (Statefile) do
       begin
         GETDATA (Statefile, state, capital);
         GUESS_CAPITAL (tries, guess, correct_guess);
         GUESSES (correct_guess)
         Tolower (str)
       end;
     close (Statefile);
     close (states);
     reset (states);
     writeln ('Great! You got these states in 1 try: ');
        while not eof (states) do
          begin
             readln (states, correct_state);
             writeln (correct_state);
          end;
     close (states)
end.
0
Comment
Question by:kazooie21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:mathought
ID: 2705481
10 points?!
0
 

Author Comment

by:kazooie21
ID: 2705721
Adjusted points from 10 to 30
0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2706740
If Ord(Str[I]) >= Ord('A')
0
 
LVL 6

Accepted Solution

by:
My name is Mud earned 120 total points
ID: 2706773
If Ord(Str[I]) >= Ord('A')
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2718854
Ord() function returns a number, not a character. That's why you can't compare against 'A'.

Besides that, you can simplify some things; convert to lower case with this code:

if str[i] in ['A'..'Z'] then str[i] = chr(ord(str[i])+32);

Better than that: as you're doing comparisons only, use all capital letters and use the already-built-in UpCase() function instead.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question