A pair of statements as single statement 
Author Message
 A pair of statements as single statement

Quote:
> I am a newbie in Pascal. I am a fairly good programmer in Clipper, but
> I am trying to get my B.S. in computer science, and I have several > questions. I will begin with one.

> They want me to write this as a single statement.....

> Age := 17 + oldage;
> Age := Newage - 5;

   Are you sure this is the exact requirement?  It doesn't seem right,
because it's contradictory: the 1st statemnt assigns a value to Age and
the 2nd assigns a different value to Age.  Combining these statements has
no purpose, since the 2nd one is the only statement which accomplishes
anything.
   It looks as though you didn't copy the assignment correctly, and that
it should be:

  NewAge := 17 + OldAge;
  Age := NewAge - 5;

   If that's the case, you have to understand operator precedence, to
know what will happen when these statement are combined.  In these
statements, the order of precedence is linear/equal, so all
subexpressions are evaluated left-to-right.  It can be coded as:

  Age := (OldAge+17)-5

   That is, the expression in the parentheses is evaluated, _then_ 5 is
subtracted from the result...which is then assigned to Age.  You have to
evaluate the 1st statement's expression completely, before you can apply
it in the 2nd statement.
   Of course, it )could_ be made even simpler by:

  Age := OldAge+12;

but that isn't doing what the instructor wants you to learn...



Wed, 18 Jun 1902 08:00:00 GMT  
 A pair of statements as single statement

I am a newbie in Pascal. I am a fairly good programmer in Clipper, but I am
trying to get my B.S. in computer science, and I have several questions. I
will begin with one.

They want me to write this as a single statement.....

Age := 17 + oldage;                    
Age := Newage - 5;

Any help would be appriciated!!!!                      



Wed, 18 Jun 1902 08:00:00 GMT  
 A pair of statements as single statement


Quote:
>I am a newbie in Pascal. I am a fairly good programmer in Clipper, but I am
>trying to get my B.S. in computer science, and I have several questions. I
>will begin with one.

And  they're teaching you Pascal?  Last I'd heard, if you were going into
Comp. Sci. you started learning C right away.  At least I did.

Quote:
>They want me to write this as a single statement.....

>Age := 17 + oldage;                
>Age := Newage - 5;

Um, that is really easy.  I would say the new line is:

Age:=Newage-5;

If you notice in the first line, Age is being given a value of
17+oldage.  In the second line, Age is given Newage-5.  Since there is no
operation in the second line to keep the value of Age before Newage-5 is
assigned to it. (If the 2nd line had said Age:=Age +/- Newage - 5, then
you could've written Age := 17+oldage +/- Newage-5.)

Quote:
>Any help would be appriciated!!!!                  

--
Mike Shepherd (aka:  the Sheepster)
If you're ever in trouble on the water, the first thing you'll
see is a bunch of maniacs in a {*filter*} boat, comin' for to carry
you home.


Wed, 18 Jun 1902 08:00:00 GMT  
 A pair of statements as single statement


Quote:
>I am a newbie in Pascal. I am a fairly good programmer in Clipper, but I am
>trying to get my B.S. in computer science, and I have several questions. I
>will begin with one.

>They want me to write this as a single statement.....

>Age := 17 + oldage;                
>Age := Newage - 5;

(Assuming that OldAge is a variable or constant and not a function
that affects NewAge ...)

I fail to see how you could possibly have a problem with this.

The outcome of the pair of statements above is totally independent
of the first statement: just throw it away and use the second one.

(If OldAge and/or NewAge are functions rather than constants or variables
 you should have said so, so I have assumed they are not.)



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. A pair of statements

2. update statement

3. SQL STATEMENT

4. SQL Statement month grouping

5. Help with SQL Statement applied to Paradox tables

6. IF statement in SQL

7. SQL statements in object inspector

8. Please try the following statement.

9. TDatasetProvider doesn't formulate correct update statement

10. Calling RTL routines in asm...end statements

11. How to retrieve info from an insert SQL statement

12. Sql statement

 

 
Powered by phpBB® Forum Software