I'm trying to learn Turbo Pascal from the book Turbo Pascal by Samuel L. Marateck, and made it near the end of chapter 3 to the exercises section on page 97, but I have no real Ideal how to write the programs that I need to make up from thin air to complete the exercises 1-27, one or two of them are do able but for the other 24 who knows, and I guess I could skip over them and continue with chapter 4 but I don't know if completing them is necessary or not, in learning Turbo Pascal so I'm kind of lost as what to do next. Does anyone know where I could find the code to the programs that go with the exercises, or else maybe I'll start over with chapter one and find out if I missed anything that can help me.

The First Exercises Is as follows just as an example of what I am referring to in the book.

1. Write the output for each of the following statements:

Writeln (5 - 8) + (4 DIV 2)); ________

Writeln (5 - (8 + 4) DIV 2); ________

Writeln ((5 - (8 + 4)) DIV 2); _______

Writeln ((5 - 8 + 4) DIV 2); ________

Writeln (5 - 8 + 4 DIV 2); _________I don't get it and the above is one the easier exercises maybe I need to take a course in math too, or at least a refresher in it.. Help..

I don't know Pascal, but in general, the best way to see what your programs do is to try them out. Write out the source in the editor and then execute it to see what it does. Math ops are done in precedence - pemdas; powers, exponents, (mul or div), (add or sub).

Writeln (5 - 8) + (4 DIV 2));

(5-8 = -3) + (4 / 2 = 2) or -1In the above, div occurs before either addition or subtraction. After that, they're all on the same level of precedence.

I don't know if it will help, but here's a pascal resource page.

Good luck.

Thanks that helps a little at least gives me a starting point, I can write the program like,

Program test;

Begin

Writeln (5 - 8) + (4 DIV 2));

Writeln (5 - (8 + 4) DIV 2);

Writeln ((5 - (8 + 4)) DIV 2);

Writeln ((5 - 8 + 4) DIV 2);

Writeln (5 - 8 + 4 DIV 2)

End.But I get a syntax error when running it and I don't know what the source is for the program, I think I need to add the Variables "VAR Something, Something: real; or integer;" before Begin, for the exercise but I don't know what the variables should be.

1) always look for "unbalanced": either parentheses or quotes,

in ANY computer language or code.

99 out of 100 they're an error, so line one output will probably be: "syntax error":

Writeln (5 - 8) + (4 DIV 2));

(note there is unmatched parenth at end of expression)

(cheat: count all ( then count all ) and subtrct, should = 0!)

2) make sure to emphasize learning about binary, boolean, and exponentiation ("powers of", especially 2 and 16) and

hexadecimal no.s. If you don't, you will probably be lost.

3) heirarchy of math ops: *, / go before +/- and always put

() ahead of other op.s, etc (I'm sure your instructor will help with this, if not already has...)

Writeln (5 - 8) + (4 DIV 2)); WRONG!Writeln (5 - (8 + 4) DIV 2);

inner: 8+4:=12, div precedes subt, so:

12 is div by 2 = 6, before being subt from 5, yields -1

(i think. I've embarassed myself to many times to be confident, but at least get the idea)Writeln ((5 - (8 + 4)) DIV 2);

inner first: 8+4=12

next inner: 5-12, = -7

-7 / 2 gives -3.5 (or -4 if integer rounding)

(neg div pos equ neg, neg div neg equ pos, same for times)

Writeln ((5 - 8 + 4) DIV 2);

inner ()result: 1. 1 div 2 is .5 or 1 if integer rounded

Writeln (5 - 8 + 4 DIV 2)

remember: DIV (or /) and mult (or *) always done FIRST!

so: 4 DIV 2 is done before anything, yieldiing 2.

then do the rest (since order is not significant in same-level arithmatic): 5-8 (-3) + result of the DIV (2) yields -1.My instructor at Wooster (1978) was Zimmerman, who co-wrote "A primer on Pascal" and had much influence on the origins of the language. We literally "punched" our programs, to cards, then waited to see what came out of the "lineprinter" (usually garbage or lots of error messages) but it was still a real "gas" working with "big" computers.

(sorry, i'm getting old... talk too much about the olde days)

ps: insert "pause"-type breaks, and display statmts into your program to target errors (i can't remember what pascal's version was for "input"). Then you can target which line caused the program to jake out.

Thank you, That explains it very well and points out where I need to focus on understanding everything, then I didn't think to check the statements for errors either, thought their syntax was already correct, forgot an important rule to never assume anything, until you test it out. Wishes I had an instructor, I'm on my own though with just the book. In the mean time I did completed a couple of the other exercises. Now I can probably finish that first one too, and get at the rest with a much clearer idea of what I'm doing. I really appreciate the help, I think I talk too much too though, Best Regards.

Ask Your Question

Weekly Poll

Do you think manufacturers should do more to reduce phone and tablet usage among kids?

Discuss in The Lounge

Poll History