Solved

how to do lower case and upper case?

Posted on 2000-04-10
1
399 Views
Last Modified: 2010-08-05
The user could enter the capital as all lower case or all upper case. How would I rework this program so it provides lower and upper case function?

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}


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)
       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
1 Comment
 
LVL 2

Accepted Solution

by:
yairy earned 20 total points
ID: 2702458
you can convert a string to
Upper by:

procedure ToLower(var str:string)
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;

// wasn't checked.

The idea is to add/sub the constant
OFFSET between upper and lower ascii.

The ToUpper function is very much similar.

read about Ord and chr....
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now