|
 |
pseudo code |
 |
09-12-2006, 06:18 PM
|
#1
|
|
Banned
Join Date: Jan 2006
Location: europe
Posts: 1,034
|
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
|
|
|
| Sponsored Links |
|
09-13-2006, 03:02 PM
|
#2
|
|
Gold Member
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
|
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.
|
|
|
09-13-2006, 09:21 PM
|
#3
|
|
Senior Member
Join Date: Sep 2004
Location: Here or there or Maryland
Posts: 514
|
Quote:
Originally Posted by Masque
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.
|
|
|
 |
|
 |
09-14-2006, 04:18 AM
|
#4
|
|
Banned
Join Date: Jan 2006
Location: europe
Posts: 1,034
|
Quote:
Originally Posted by Fearless Virgin
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
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
|
|
|
 |
|
 |
09-14-2006, 02:50 PM
|
#5
|
|
Gold Member
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
|
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
|
|
|
09-14-2006, 03:00 PM
|
#6
|
|
Banned
Join Date: Jan 2006
Location: europe
Posts: 1,034
|
that's not pseudo code
|
|
|
09-14-2006, 03:13 PM
|
#7
|
|
Gold Member
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
|
so a pseudo code has to be IF statements?  Lol...I'm just telling you how I would've done it <<
__________________
Thankies Razyni
|
|
|
09-14-2006, 03:18 PM
|
#8
|
|
Banned
Join Date: Jan 2006
Location: europe
Posts: 1,034
|
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
|
|
|
09-14-2006, 03:22 PM
|
#9
|
|
Gold Member
Join Date: Aug 2005
Location: Under My Skin
Posts: 7,503
|
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
|
|
|
09-15-2006, 02:27 AM
|
#10
|
|
Senior Member
Join Date: Sep 2004
Location: Here or there or Maryland
Posts: 514
|
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.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 03:15 AM.
| |