/    Sign up×
Community /Pin to ProfileBookmark

Having Trouble With Pseudocode – Help Please :)

Hi everybody, ?

I am trying to convert some of my programs into pseudocode but I really do not know what I’m doing. ? Some help would be very much appreciated. ?

This is my first program and my outcome of pseudocode for it:

[code]
<html>
<head>
<title>Largest or Equals</title>
<script type = “Text/JavaScript”>
<!– Hides the JavaScript from browsers
var number1 = parseInt(prompt(“Please enter your first number…”,&#8221;&#8221;));
var number2 = parseInt(prompt(“Please enter your second number…”,&#8221;&#8221;));

if (number1 > number2)
{
alert(number1 + ” is the largest number!”);
}
else
if (number2 > number1)
{
alert(number2 + ” is the largest number!”);
}
else
{
alert(“Both of the numbers are equal!”);
}
// Ends the hiding comment –>
</script>
</head>
<body>
</body>
</html>
[/code]

Pseudocode for it:

[code]
read in first number
read in second number

if first number > second number then

write out first number is the largest

else
if second number > first number then

write out second number is the largest

else

write out first number and second number are equal
[/code]

This is my second program, but now I’m totally confused about what to do for functions and loops, as well as their conditions, etc:

[code]
<html>
<head>
<title>Powers from Function</title>
<script type = “Text/JavaScript”>
<!– Hides the JavaScript from browsers
function powers()
{
var number = parseInt(prompt(“Please enter a number to view its powers…”,&#8221;&#8221;));

for (i = 0; i <= 10; i ++)
{
document.write(number + ” to the power of ” + i + ” = ” + Math.pow(number,i));
document.write(“<br />”);
}
}
// Ends the hiding comment –>
</script>
</head>
<body>
<input type=”button” onclick=”powers()” value=”Powers Calculator”/>
</body>
</html>
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@AmphidamasauthorDec 04.2008 — Check here, it may help:

http://en.wikipedia.org/wiki/Pseudocode[/QUOTE]


Thanks. I understand that there are no specific guidelines to follow for pseudocode, but there must be a good reference out there somewhere.

Specifically, it's what I need to write for the conditions within the For Loop that's confusing.
Copy linkTweet thisAlerts:
@mintedjoDec 04.2008 — Anything that describes what's going on is pseudocode.

So for instance a for loop could be written in pseudocode as
[CODE]for 0 to 10 do
an action
another action[/CODE]


Pseudocode can range from a very vague description of whats happening to almost an exact representation of the actual code that it would be implemented with. Why don't you post what you think and if other people can make sense of it its probably right.

EDIT: I just noticed you said the for loop conditions were confusing you. What exactly is confusing about it?
Copy linkTweet thisAlerts:
@AmphidamasauthorDec 04.2008 — 
EDIT: I just noticed you said the for loop conditions were confusing you. What exactly is confusing about it?[/QUOTE]


Just how I'm best off writing them out in pseudocode. I think I've got it now though. ? I'll post up my codes in a few moments.
Copy linkTweet thisAlerts:
@AmphidamasauthorDec 04.2008 — Here they are: ? Look forward to reading the answers.

Program No. 1
<i>
</i>read in first number
read in second number

if first number &gt; second number then

<i> </i> write out first number is the largest

else
if second number &gt; first number then

<i> </i> write out second number is the largest

<i> </i> else

<i> </i> write out first number and second number are equal


Program No. 2
<i>
</i>declare a function called &amp;#8220;powers&amp;#8221;

<i> </i> read in number

<i> </i> loop for i when i &lt;= 10 in increments of 1

<i> </i> write out number to the power of i
<i> </i> write out line break

declare a button in the body to run the function &amp;#8220;powers&amp;#8221;


Program No. 3
<i>
</i>declare a function called &amp;#8220;nametitlecase&amp;#8221;

<i> </i> read in split username

<i> </i> loop for i when i &lt; split username length in increments of 1
<i> </i> loop from indices 0 until indices 1 then uppercase substring
<i> </i> loop again from indices 1 and lowercase substring

<i> </i> read in join username

<i> </i> return username

everything below this point is declared in the body

declare empty text field called &amp;#8220;username&amp;#8221;

two line breaks

declare a button which passes the value entered in the field &amp;#8220;username&amp;#8221; to the function &amp;#8220;nametitlecase&amp;#8221; and returns the result in the field &amp;#8220;result&amp;#8221;

two line breaks

declare empty text field called &amp;#8220;result&amp;#8221;


Program No. 4
<i>
</i>read in number

loop for i when i &lt;= number in increments of 1

<i> </i> if i%2 is equal to 0

<i> </i> write out i + even
<i> </i> write out line break

<i> </i> else

<i> </i> write out i + odd
<i> </i> write out line break
Copy linkTweet thisAlerts:
@AmphidamasauthorDec 04.2008 — Could anybody comment on the pseudocode's please? Just so I know if I've done anything wrong, etc.

Thank you.
×

Success!

Help @Amphidamas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...