Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gameguy3001

macrumors member
Original poster
Feb 8, 2007
96
0
Saskatoon, SK
For a Computer Science class I'm taking. We are giving a algebraic equation and asked to write it in Pseudocode. I know I have to create variables for it but I'm not sure what the equation should look like.

If someone could post a example of what a equation could be and its equivalent in Pseudocode that would help a lot.

Thanks
 
Code-wise: int var1 = 40; int var2 = 30; int newValue = var1 + var2;

Pseudo-wise: a + b = c

Of course the equations are usually more complex, but this is a basic look. There really isn't anything to it.
 
Pseudo-wise: a + b = c

Don't you think that should be c = a + b? Pseudo-code is definitely not math. You still need to show assignment similar to how we do it in code. a + b = c looks like you're trying to assign a+b the value of c, which is nonsense.

In pseudo-code, the symbols you use really aren't terribly important, as long as you get the correct idea across. The above works, but I often see arrows used to make the assignment more explicit, as in the following:

c <- a+b

It's really all your preference, unless you get a teacher who's really strict about it. (You'd be surprised...)
 
Don't you think that should be c = a + b? Pseudo-code is definitely not math. You still need to show assignment similar to how we do it in code. a + b = c looks like you're trying to assign a+b the value of c, which is nonsense.

In pseudo-code, the symbols you use really aren't terribly important, as long as you get the correct idea across. The above works, but I often see arrows used to make the assignment more explicit, as in the following:

c <- a+b

It's really all your preference, unless you get a teacher who's really strict about it. (You'd be surprised...)

I kinda like the idea of right handed assignment statements. I have vague memories of some language that does it. a + b -> c

I can even see uses for a programming language that would accept assigning a value to an equation. Constrain a and b such that their sum is c. Each would then be an array of possible values.
 
Don't you think that should be c = a + b? Pseudo-code is definitely not math. ...

Well he specifically mentioned pseudo code for an equation so that's why I did it like that. As far as I've ever seen there's no rules for pseudo code, but I understand your point. Usually when I do pseudo code (which is rare) I use sentence form, kind of like AppleScript.
 
I kinda like the idea of right handed assignment statements. I have vague memories of some language that does it. a + b -> c

I can even see uses for a programming language that would accept assigning a value to an equation. Constrain a and b such that their sum is c. Each would then be an array of possible values.

On a Texas Instrument calculator you set values to your variables in this way. The language used by this calculators is similar to BASIC.
 
I kinda like the idea of right handed assignment statements. I have vague memories of some language that does it. a + b -> c

I can even see uses for a programming language that would accept assigning a value to an equation. Constrain a and b such that their sum is c. Each would then be an array of possible values.

COBOL works math to the right, except for the COMPUTE statement:

Code:
ADD A TO B GIVING C.

It's also good for a pseudocode experience.

I wouldn't suggest using 1 character variable names, though, unless you're using a calculator.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.