Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

easiest way to do upper case and lower case

Posted on 2000-04-11
4
Medium Priority
?
220 Views
Last Modified: 2010-04-16
What's the easiest way to do upper case and lower case on this program?

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
4 Comments
 

Author Comment

by:kazooie21
ID: 2705722
Adjusted points from 5 to 20
0
 
LVL 6

Accepted Solution

by:
My name is Mud earned 60 total points
ID: 2706771
VAR
  STRTest: String;

Procedure Upper(Var Str: String);
Var
  I: Byte;
Begin
  For I:=1 to Length(Str) Do
    Str[I]:=UpCase(Str[I]);
End;

Procedure Lower(Var Str: String);
Var
  I: Byte;
Begin
  For I:=1 to Length(Str) Do
    If Str[I] in ['A'..'Z'] Then
      Str[I]:=Char(Ord(UpCase(Str[I])) + 32);
End;

Begin
  STRTest:='HeLlO WoRd... @#$%^';
  Upper(STRTest);
  WriteLn(STRTest);
  STRTest:='HeLlO WoRd... @#$%^';
  Lower(STRTest);
  WriteLn(STRTest);
End.
0
 
LVL 1

Expert Comment

by:bakry99
ID: 2706789

you can do it as functions


function Tolower(str: string): string;
var i: integer;
begin
  for i:= 1 to length (str) do
     if str[i] in['A'..'Z'] then
     str[i] := chr(ord(str[i]) + 32);
 ToLower := str;
   end; {tolower}

function ToUpper(str: string): string;
var i: integer;
begin
  for i:= 1 to length (str) do
    str[i] := UpCase(str[i]);
  ToUpper:= str;
   end; {toUpper}

Regards Bakry

0
 
LVL 3

Expert Comment

by:vikiing
ID: 2718857
¿What's the reason to use a ToUpper() function when UpCase() (built-into compiler itself) does the same job?
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
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 …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 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