Go Back   #1 Chat Avenue Message Boards > Life Forums > Homework Help
Register Blogs FAQ Calendar Gallery Mark Forums Read

Reply
 
Thread Tools Display Modes
pseudo code
Old 09-12-2006, 06:18 PM   #1
Masque
Banned
 
Masque's Avatar
 
Join Date: Jan 2006
Location: europe
Posts: 1,034
Masque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond repute
Default pseudo code

Study the following pseudo code – highlight the fault(s) in it


Set total to zero
Set grade counter to zero
While grade counter is less than or equal to eighteen
Input the next grade
Add grade to the total
Set the class average to the total divided by seventeen
Print the average
Masque is offline   Reply With Quote
Sponsored Links
Old 09-13-2006, 03:02 PM   #2
Fearless™
Gold Member
 
Fearless™'s Avatar
 
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
Fearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond repute
Default

Lol. Not sure how this works but this is how I would've done it...

var
total, grade, counter, average: integer;

begin

total:=0;
counter:=0;

if counter <= 18 then

begin
inc(counter);
grade:=strtoint(inputbox('grade','enter grade',''));
total:=total+grade;
end;

average:=total/18;

showmessage('the average is '+inttostr(average));
end;

Lol. I don't even know what if this is pseudo code or what
At my school, we use Delphi. Don't know if you've heard of it. Anyhow...the procedures might be a little different than yours?...idk.

edit: when you said 'print the average'...do you mean print it out via a printer, or just display it? Oh, and I didn't use the compiler, so there could be some error in my code << yeah...so it may not run, etc.
__________________


Thankies Razyni

Last edited by Fearless™; 09-13-2006 at 03:04 PM.
Fearless™ is offline   Reply With Quote
Old 09-13-2006, 09:21 PM   #3
Western_Samurai
Senior Member
 
Western_Samurai's Avatar
 
Join Date: Sep 2004
Location: Here or there or Maryland
Posts: 514
Western_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond repute
Default

Quote:
Originally Posted by Masque View Post
Study the following pseudo code – highlight the fault(s) in it


Set total to zero
Set grade counter to zero
While grade counter is less than or equal to eighteen
Input the next grade
Add grade to the total
Set the class average to the total divided by seventeen
Print the average
While grade counter is less than or equal to 18. That's a problem. Your class size is 17 so you only need to input 17 grades. Therefore it should be while grade counter is less than or equal to 17 or less than 18. Either would work.
__________________
Western_Samurai is offline   Reply With Quote
Old 09-14-2006, 04:18 AM   #4
Masque
Banned
 
Masque's Avatar
 
Join Date: Jan 2006
Location: europe
Posts: 1,034
Masque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond repute
Default

Quote:
Originally Posted by Fearless Virgin View Post
Lol. Not sure how this works but this is how I would've done it...

var
total, grade, counter, average: integer;

begin

total:=0;
counter:=0;

if counter <= 18 then

begin
inc(counter);
grade:=strtoint(inputbox('grade','enter grade',''));
total:=total+grade;
end;

average:=total/18;

showmessage('the average is '+inttostr(average));
end;

Lol. I don't even know what if this is pseudo code or what
At my school, we use Delphi. Don't know if you've heard of it. Anyhow...the procedures might be a little different than yours?...idk.

edit: when you said 'print the average'...do you mean print it out via a printer, or just display it? Oh, and I didn't use the compiler, so there could be some error in my code << yeah...so it may not run, etc.
Thanks a lot, but it's the wrong code example of pseudo is...

if credit card number is valid
execute transaction based on number and order
else
show a generic failure message
end if

Quote:
Originally Posted by Western_Samurai View Post
While grade counter is less than or equal to 18. That's a problem. Your class size is 17 so you only need to input 17 grades. Therefore it should be while grade counter is less than or equal to 17 or less than 18. Either would work.
ahhh, i get it now. yeah that seems about right. thanks
Masque is offline   Reply With Quote
Old 09-14-2006, 02:50 PM   #5
Fearless™
Gold Member
 
Fearless™'s Avatar
 
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
Fearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond repute
Default

Lol...I said I didn't know if it was right... Anyhow, an IF statement should work the same as a WHILE loop if the constant is the same...but what I would do is...

Say you don't know how many people are in your class...

1) Set total to 0;
2) Set counter to 0;

3) Input the first mark; //initialise
4) WHILE mark is not equal to 000 do //test

begin
5) Assign total to total + mark;
6) increment counter; //change
7) input the next mark;
end;

Assign average to total divided by counter;

^^ That way, the loop will carry on, until the user tells it to stop (by entering 000)

So you can have how ever many marks you want, and it will still work out. i.e. it doesn't matter if you have 17 or 18 students...

So I think the best is not to use the grade counter, but the mark.
__________________


Thankies Razyni
Fearless™ is offline   Reply With Quote
Old 09-14-2006, 03:00 PM   #6
Masque
Banned
 
Masque's Avatar
 
Join Date: Jan 2006
Location: europe
Posts: 1,034
Masque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond repute
Default

that's not pseudo code
Masque is offline   Reply With Quote
Old 09-14-2006, 03:13 PM   #7
Fearless™
Gold Member
 
Fearless™'s Avatar
 
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
Fearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond repute
Default

so a pseudo code has to be IF statements? Lol...I'm just telling you how I would've done it <<
__________________


Thankies Razyni
Fearless™ is offline   Reply With Quote
Old 09-14-2006, 03:18 PM   #8
Masque
Banned
 
Masque's Avatar
 
Join Date: Jan 2006
Location: europe
Posts: 1,034
Masque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond reputeMasque has a reputation beyond repute
Default

IF statements are even used in spreadsheats like in excel lol...

and no i just had to study the pseudo code and say what was wrong with it. could of corrected it, but just had to say what was wrong with it like western_samurai did
Masque is offline   Reply With Quote
Old 09-14-2006, 03:22 PM   #9
Fearless™
Gold Member
 
Fearless™'s Avatar
 
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
Fearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond reputeFearless™ has a reputation beyond repute
Default

I know you can use IF in excel...
Anyhow, let me rework my post...

Set total to 0
Set counter to 0

Input the first mark
WHILE mark is not equal to 000 do
>>Assign total to total plus mark
>>increment counter
>>input the next mark;
Assign average to total divided by counter

So is that pseudo code now? I'm just saying that it's better to use a while loop, because the way you did it...you can only input 17 marks...whereas if you use a while loop, you can enter how ever many marks as you like...
__________________


Thankies Razyni
Fearless™ is offline   Reply With Quote
Old 09-15-2006, 02:27 AM   #10
Western_Samurai
Senior Member
 
Western_Samurai's Avatar
 
Join Date: Sep 2004
Location: Here or there or Maryland
Posts: 514
Western_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond reputeWestern_Samurai has a reputation beyond repute
Default

Pseudo-code is just a way of writing out the steps of the algorithm in a systematic way but using english syntax without any particular coding syntax. A textbook would tell you that pseudo-code should be able to be translated into any programming language so you shouldn't include words like if or while as these may not conceivably be in every language. Instead you would say "conditionally" for if and "repeat" for while but who gives a crap what a text book says, I say do what works best for you, in the end the pseudo-code is for you the programmer and no one else.
__________________
Western_Samurai is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 1999-2009 - #1 Chat Avenue - Free chat rooms for adults, gays, kids, singles, teens and more.