Board index » delphi » Beginner needs help!

Beginner needs help!

I need to differentiate between two strings in an array.  Specifically I
need to be able to tell a question from a non-question.  is there a way to
pick out the question mark at the end of the string?  I would like to put
it in the following line:

while _______________________ do

-Mike

 

Re:Beginner needs help!


In article <48fock$...@madeline.INS.CWRU.Edu>, m...@po.cwru.edu says...

Quote

>I need to differentiate between two strings in an array.  Specifically I
>need to be able to tell a question from a non-question.  is there a way to
>pick out the question mark at the end of the string?  I would like to put
>it in the following line:

>while _______________________ do

>-Mike

Hi
As you said you were a begginer I thought you might
like a specific bit of code to demonstrate what you want,
you should be able to paste this in an play.

program test;

var line: string;         { Init variable }

 { returns true if line has a ? at the end }
function Question(var line: string): boolean;
var TotChars: byte;
begin
      { find how long the line is }
    TotChars:= length(line);

      { test to see if the last char is a ? }
    Question:= Line[TotChars] = '?';
end;

 { returns true if line has a ? any where in it }
function Question2(var line: string): boolean;
begin
    Question2:= pos('?', line)<>0;
end;

begin
    line:= 'A question ?';      { start with ? so the loop loops }
    While  Question(line) do
    begin
       Write('Input test string ');
       readln(Line);
    end;

    line:= '? A question';      { start with ? so the loop loops }
    While  Question2(line) do
    begin
       Write('Input the other test string ');
       readln(Line);
    end;
end.

I hope this is of use

--------------------------------------------------
/\/\ | |( [-    no e-mail yet      +44 1252 335805
Views are my personal views and not of my employer
-----------------------X--------------------------

Re:Beginner needs help!


Quote
Tom Wheeley <t...@tsys.demon.co.uk> wrote:
>In article <48fock$...@madeline.INS.CWRU.Edu>
>           m...@po.cwru.edu "Mike Anderson" writes:

>> I need to differentiate between two strings in an array.  Specifically I
>> need to be able to tell a question from a non-question.  is there a way to
>> pick out the question mark at the end of the string?  I would like to put
>> it in the following line:

>> while _______________________ do

>ehh?
>If you _know_ that the only the last character is the ? (ie there will be no
>spaces or punctuation after the ?), then simply:

You could search the whole string for a '?' using something similar to
this :

WHILE (POS(?,arrayname[rownumber])>0 DO

The POS command looks through the string in array "arrayname" on row
"rownumber" and if it matches it will return a value telling you the
position from the start of the string that the "?" appears. I.e. if:

Hello? Testing 123

...is stored in arrayname[1] then this line would return a value of
"6".

Mike.

Re:Beginner needs help!


In article <48fock$...@madeline.INS.CWRU.Edu>
           m...@po.cwru.edu "Mike Anderson" writes:

Quote
> I need to differentiate between two strings in an array.  Specifically I
> need to be able to tell a question from a non-question.  is there a way to
> pick out the question mark at the end of the string?  I would like to put
> it in the following line:

> while _______________________ do

ehh?
If you _know_ that the only the last character is the ? (ie there will be no
spaces or punctuation after the ?), then simply:

var
   TempStr: String;
begin
   if TempStr[Length(TempStr)]='?' then writeln('Question!');
end;

To check for a ? in the whole string, then you'll need a loop.

--
Tom Wheeley, <holyhorns>, MAMSWWBUW
* TQ 1.0 * From the rec.humor.funny one-liner file.
Regarding Michael Jackson ---
Only in a America can a poor black boy grow up to be a rich white woman.

Re:Beginner needs help!


Re:Beginner needs help!


Quote
>why wont my hours less than or equal to 40<
>calculate times rate and write??<
>what am I doing wrong and/or not seeing here?<

PROGRAM Employee_Payroll_Per_Rate (input, output);

USES
  WinCrt;                  {needed with WFW 3.11}

VAR
  enum : integer;     {emp# - INPUT}
  hrs,                      {hrs worked - INPUT}
  rate,                     {hrly rate - INPUT}
  gross,                   {hrs_rate+hrs_ot - CALC+OUTPUT}
  hrs_rate,              {hrs<=40*rate - CALC+OUTPUT}
  hrs_ot,                 {hrs-40*ot_rate - CALC+OUTPUT}
  ot_rate                 {rate/2+rate - CALC+OUTPUT}
     : REAL;

BEGIN

  READLN;          {toggle printer on}
                                 {Input Info}
  WRITE('EMPLOYEE NUMBER:');

  READLN(enum);

  WRITE('HOURS WORKED: ');

  READLN(hrs);

  WRITE('HOURLY RATE:  $');

  READLN(rate);
                               {output}
  WRITELN;

    ot_rate := rate/2+rate;

    if hrs<=40
      then
        begin
          hrs_rate := hrs*rate;
        end
      else
        begin
           hrs_ot := (hrs-40)*ot_rate;
  end;
                                           {****NOT CALCULATING****}
  WRITE('REGULAR PAY:  $',hrs_rate:10:2);      {hrs<=40*rate}

  WRITELN;
                            {****CALC S OK****}
  WRITE('OVERTIME PAY: $',hrs_ot:10:2);        {hrs>40*ot_rate}

  WRITELN;

  gross := hrs_rate + hrs_ot;
                            {****CALCS OK****}  
  WRITE('GROSS PAY:    $',gross:10:2);         {hrs_rate+ot_pay}

  READLN
                                               {toggle printer off}

END.
  ??
thanks

Re:Beginner needs help!


Re:Beginner needs help!


Quote
Mike Anderson <m...@po.cwru.edu> wrote:
>I need to differentiate between two strings in an array.  Specifically I
>need to be able to tell a question from a non-question.  is there a way to
>pick out the question mark at the end of the string?  I would like to put
>it in the following line:
>while _______________________ do
>-Mike

LastChr := COPY(urstring, Length(urstring),1);
While LastChr = '?' Do  etc.

<clifp...@airmail.net>

Re:Beginner needs help!


Re:Beginner needs help!


Just a hint.  Consider that the IF-THEN-ELSE will only take one
(either THEN or ELSE) of the paths.  Try testing with hours above
40 and below 40 and you should see what is wrong.

Wayne

Quote
In article <48j3ed$...@nnrp3.news.primenet.com> CS1A wrote:
>Date:       Fri, 17 Nov 1995 23:42:31 GMT
>From:       ftrsb...@primenet.com (CS1A )
>Newsgroups: comp.lang.pascal.borland
>Subject:    another beginner needs help!

>>why wont my hours less than or equal to 40<
>>calculate times rate and write??<
>>what am I doing wrong and/or not seeing here?<

>PROGRAM Employee_Payroll_Per_Rate (input, output);

>USES
>  WinCrt;                  {needed with WFW 3.11}

>VAR
>  enum : integer;     {emp# - INPUT}
>  hrs,                      {hrs worked - INPUT}
>  rate,                     {hrly rate - INPUT}
>  gross,                   {hrs_rate+hrs_ot - CALC+OUTPUT}
>  hrs_rate,              {hrs<=40*rate - CALC+OUTPUT}
>  hrs_ot,                 {hrs-40*ot_rate - CALC+OUTPUT}
>  ot_rate                 {rate/2+rate - CALC+OUTPUT}
>     : REAL;

>BEGIN

>  READLN;          {toggle printer on}
>                                 {Input Info}
>  WRITE('EMPLOYEE NUMBER:');

>  READLN(enum);

>  WRITE('HOURS WORKED: ');

>  READLN(hrs);

>  WRITE('HOURLY RATE:  $');

>  READLN(rate);
>                               {output}
>  WRITELN;

>    ot_rate := rate/2+rate;

>    if hrs<=40
>      then
>        begin
>          hrs_rate := hrs*rate;
>        end
>      else
>        begin
>           hrs_ot := (hrs-40)*ot_rate;
>  end;
>                                           {****NOT CALCULATING****}
>  WRITE('REGULAR PAY:  $',hrs_rate:10:2);      {hrs<=40*rate}

>  WRITELN;
>                        {****CALC S OK****}
>  WRITE('OVERTIME PAY: $',hrs_ot:10:2);        {hrs>40*ot_rate}

>  WRITELN;

>  gross := hrs_rate + hrs_ot;
>                        {****CALCS OK****}    WRITE('GROSS PAY:    $',gross:10:2);        
> {hrs_rate+ot_pay}

>  READLN
>                                               {toggle printer off}

>END.
>  ??
>thanks

Re:Beginner needs help!


Re:Beginner needs help!


Quote
> To check for a ? in the whole string, then you'll need a loop.

On a simmilar note...how could one search a string for a substring
such as 'fish' for example..and then change it to another
string..such as 'hello'?

Re:Beginner needs help!


Re:Beginner needs help!


Quote
On Fri, 17 Nov 1995, CS1A wrote:
> >why wont my hours less than or equal to 40<
> >calculate times rate and write??<
> >what am I doing wrong and/or not seeing here?<

> [QP-NewsScissors v1.3 activated]

>     if hrs<=40
>       then
>         begin
>           hrs_rate := hrs*rate;
>         end
>       else
>         begin
>            hrs_ot := (hrs-40)*ot_rate;

how about this:

hrs_rate := hrs*rate;
if hrs > 40 then
  hrs_ot := (hrs - 40)*ot_rate;

Your problem is that you're only calculating the regular hours if you
don't have any overtime hours.  You were making the problem more
complicated than it should be IMO. :)

    ________________________________________________________________________
   / Joshua Shagam                    /    (Quantum Porcupine / Versatile) /
  / mailto:JSha...@nmsu.edu          /       http://web.nmsu.edu/~jshagam /
 / phone://1.505.645.3856/~joshua   /  for the Quantum Porcupine Archive /
/__________________________________/____________________________________/
 Stop the execution of King Louis XIV!  If you agr-- oops, too late! :)

Re:Beginner needs help!


Go to page: [1] [2]

Other Threads