Pseudocode help


Off-Topic Discussions


I have just discovered pseudocode, and it looks just like real code to me. So I have to ask is it real code or just a way to let you know what you need to do while writing the real code. My instructor is not good at explaining things.

If they are different then a comparison of a simple code in C or Linden that adds two numbers would be helpful.

Liberty's Edge

It's been so long since I coded I couldn't do it without looking stuff up, but pseudocode is not a real computer language.

Rather it's a structured variant of natural language use for roughing out algorithms and programming structures.

You'll see it mostly in academic (including instructional materials) and scientific contexts.


Pseudocode is not real code; pseudocode is simply English (or another) real language structured roughly to look like your computer language of choice.

Your example is actually a little too simple; pseudocode to add two numbers would look an awful lot like real code. But here's something a bit more complex that would give an example.

/* version 1 in rough pseudocode */
solveVolume
{
read in numbers for length, width, and depth
total volume is length * width * depth
return total volume
}

/* version 2 in slightly more refined pseudocode */
solveVolume()
{
int x, y, z, t;
read x
read y
read z
t = x * y * z;
return t;
}

/* version 3 which should almost compile */
void solveVolume()
{
int x, y, z, t; /* length, width, depth, and total, respectively */
scanf(" %d", &x); /* read in all variables */
scanf(" %d", &y);
scanf(" %d", %z);
t = x * y * z; /* total is product of all dimensions */
return t;
}

There's a good example here of pseudocode to solve a more complicated problem, how to play Monopoly. This particular problem might take hundreds of lines if it were in actual code (rolling dice, for example, can be surprisingly complex), but it fits comfortably into a page and gives you a good idea of how to play without bogging own in details like "what's the rent on Illinois Avenue?"

The Exchange

Its like coding in basic except there is more c++ terminology thesedays.
Key words that do stuff are complex coding. I suppose you might even consider it a flowchart.

Liberty's Edge

Pseudocode looks like whatever the author wants it to. Usually it's a mix of formated natural language, mathematics, and primitives similar to the author's prefered programing language.

See Wikipeia's entry for some examples and discussion.


Thanks.

Community / Forums / Gamer Life / Off-Topic Discussions / Pseudocode help All Messageboards

Want to post a reply? Sign in.