HELP!! Dev-Pascal First Program...

I need major help. I am in an intro to computer programming class in school - but it feels more like ADVANCED programming to me. I can't get the instructor to return emails and I'm panicking.

Here is the program info...

I need to convert the equation '(b*b) - 4ac' into Pascal expressions. Then I need to write a program that will read in the values of a, b, and c and use these values to solve the expression. My output should be in tabular format and look something like this:

Right, I won't code for you, but I'll try to give you all you need to know. Let's break down what you need to do:

You have variables, so...
1) Let the computer know you need to have variables.

You need to read a, b and c from the console. Remember the guidelines up there?
2) Need a procedure to read stuff from the console, namely, a b c.

You need to use a formula... look at the guidelines again and ...
3) Need a function which processes a, b and c and returns the result of the formula.

Need to show the result to the user, so...
4) You either do that in the main program, or you can do an output procedure.

Four steps, that sounds about easy enough, right? So here's what you need to know codewise (you already sort of know the syntax).

Variables come in different types. Since you're only calculating, I'm guessing your variables are going to be things like 1, 2, 3, 4, 5, 6, 2386 and so forth. Those are integers, so you need to allocate memory space for three integer values - a, b, and c.

Where myvar is the name you want to give your variables, and vartypes are the type of variable (strings, integers, reals, etc).

You know what each procedure and function is going to do, so you can write the main program with each step in turn, and then move on to write the actual functions and procedures.

Functions return values, so when you call a function, generally, you'll have something like:

Code:

myVar := myFunction(myArgument1, myArgument2);

Procedures don't need that, since they don't return values. However, they can change the arguments you've passed on to them.

When you define a function, all its arguments should be const, constants. That's because a function doesn't change any variables. A procedure might, so any variables you're planning on changing there should have var before them. I'll exemplify:

Notice the constant doesn't get changed, but that all the variables that are assigned as "var" within the argument section can be changed with no problems.

Hopefully you know how to handle a procedure. There's input though. Well, that's simple. All you need is a Readln(myVar). Obviously, the user needs to know what the computer wants, so a "Write("Give me the number a: ");" and then a Readln(a); would probably work better.

Now, a could be a var within a procedure called "getMyInput"... so could b, and c. They could all be within a single procedure.

How about functions? Well, it's the same as procedures, but everything passed is a constant, and there's that thing near the end:

Code:

function myFunction(myArguments): varType;

See that varType? Remember when I told you functions returned some value? Well, the computer's got to know what type of variable everything is, so in your example, you're probably returning an integer. Just write integer there and you'll be OK.

Right. So, all you need now is a function with the expression, and you're off!

To tell the function to return a variable, you assign the function name, like so: