> Yes you are correct, this is a mistake in the

> textbook regarding Algorithm 8.3. The question

> will not be marked but you will get full credit

> for it.

>

> In the previous edition the algorithm was phrased

> slightly differently but correct and we did not

> spot the change in this edition, sorry about this.]]>

Contact your lectures if you want to know what they want to see.]]>

> The book is screwed .... it was mention somewhere

> in one of the posts. Marks for the question will

> be given for attempting the pseudo code and not

> for accuracy...

That is not what the lecturer said in this thread...]]>

1. if (the number is between 90 and 100, inclusive) then 1.1 Set the grade to "A" End if 2. if (the number is between 80 and 89, inclusive) then 2.1 Set the grade to "B" End if ...

Do I have a "wrong" version of the textbook? I feel cheated. I also want an incorrect textbook! Anyone want to swop? :)]]>

In the previous edition the algorithm was phrased slightly differently but correct and we did not spot the change in this edition, sorry about this.]]>

The options for answers to the questions is giving it away... Error in the textbook. Don't worry about it. You spot the mistake now feel good about yourselft.

Pick the answer you know the lectures want to see and get your one point ;-)]]>

2) To be honest was not really paying much attention to the detail first time. I tend to filter out errors in pseudocode automatically as I'm use to working on daily bases with other peoples code.]]>

OK, I see the problem. The pseudocode in the book can easily be misinterpreted.

You are correct in literally translating the pseudocode but there is no correction to this in their errata.

This algorithm is a classic example of the danger of pseudocode. Not everybody will interpret it the way you wrote it, or in this example, the way it was meant to be written, or is this intended?

I'm not knocking the principal, even I use it to document algorithms, but using LaTeX symbols can cause problems. I would rather have written:

if SCORE between (100 AND 90)

...because even if you swop it, if SCORE between (90 AND 100), you will still end up with the same code.]]>

The book states:

If(100 >= score >= 90) grade = A *This is correct*

Then the book states:

If(80 >= score >=89) grade = B

But hang onÃ¢â‚¬Â¦ this is not rightÃ¢â‚¬Â¦ should it not read:

If(89 >= score >=80) grade = B

And then the book states:

If(70 >= score >= 79) grade = C

But hang onÃ¢â‚¬Â¦this is not rightÃ¢â‚¬Â¦should it not read:

If(79 >= score >= 70) grade = C

Need I go on?

The code that I wrote is obviously wrong and that is the whole point Ã¢â‚¬â€œ itÃ¢â‚¬â„¢s based on what the book says.]]>

IF 100 >= score% AND score% >= 90 THEN grade$ = "A" ... correct

IF 80 >= score% AND score% >= 89 THEN grade$ = "B" ... wrong

IF 70 >= score% AND score% >= 79 THEN grade$ = "C" ... wrong

IF 60 >= score% AND score% >= 69 THEN grade$ = "D" ... wrong

IF 0 >= score% AND score% >= 59 THEN grade$ = "F" ... wrong

THIS IS WHAT YOU SHOULD HAVE DONE:

IF 89 >= score% AND score% >= 80 THEN grade$ = "B"

IF 79 >= score% AND score% >= 70 THEN grade$ = "C"

IF 69 >= score% AND score% >= 60 THEN grade$ = "D"

IF 59 >= score% AND score% >= 0 THEN grade$ = "F"

You swapped the values around. Again do not put values before variables, experience has taught me and corrected you :-)]]>

100 Ã¢â€°Â¥ SCORE Ã¢â€°Â¤ 90

translates to

( 100 Ã¢â€°Â¥ SCORE ) Ã¢â€°Â¤ 90 becomes 100 >= SCORE and swap it to SCORE <= 100 (you are just swapping)

100 Ã¢â€°Â¥ ( SCORE Ã¢â€°Â¤ 90 ) becomes SCORE <= 90

so we then have

IF SCORE <= 100 AND SCORE >= 90

This is the correct way to write an if statement. The way you have done it is prone to failure (experience has taught me). I've debugged hundreds of lines due to this mistake.

BEWARE OF PSEUDOCODE: 100 Ã¢ÂªÂ° SCORE Ã¢ÂªÂ¯ 90 is very common and has more a mathematical background than development. Pseudocode has no standards or even guidelines and is merely a neutral way of writing a code concept.

PS: I have to edit this damn post cause the OSPREY upgrade is screwed with character underlines.]]>

-------------------------------------

score% = put_your_number_here

IF 100 >= score% AND score% >= 90 THEN grade$ = "A"

IF 80 >= score% AND score% >= 89 THEN grade$ = "B"

IF 70 >= score% AND score% >= 79 THEN grade$ = "C"

IF 60 >= score% AND score% >= 69 THEN grade$ = "D"

IF 0 >= score% AND score% >= 59 THEN grade$ = "F"

PRINT grade$

--------------------------------------

Why did you change the algorithmÃ¢â‚¬â„¢s operators? What you wrote there is not what the algorithm states.

Algorithm Example:

If (score <= 80 && score >= 89) grade = Ã¢â‚¬ËœBÃ¢â‚¬â„¢ ;

Your version:

If(score >=80 && score <= 89) grade=Ã¢â‚¬â„¢BÃ¢â‚¬â„¢;

Your version will work because you have fixed the algorithm (as common sense dictates)

Since the errata do not indicate that there are any problems with this algorithm, I would like think there is something else IÃ¢â‚¬â„¢m missing (or maybe not)]]>

Your code should look like this. Run it with different values and then you will understand.

#include <iostream> using namespace std; int main () { char grade; int score; cout << "Please enter score: "; cin >> score; if (score >= 90 && score <= 100) grade = 'A'; if (score >= 80 && score <= 89) grade = 'B'; if (score >= 70 && score <= 79) grade = 'C'; if (score >= 60 && score <= 69) grade = 'D'; if (score >= 0 && score <= 59) grade = 'F'; cout << "Your grade is: " << grade << endl; } // eof]]>

1.) If the score is smaller or equal to 100, or bigger or equal to 90, then grade = A (which makes sense)

2.) If the score is smaller or equal to 80, or bigger or equal to 89, then grade = B (which does not make sense)

3.) If the score is smaller or equal to 70, or bigger or equal to 79, then grade = C (which does not make sense)

4.) If the score is smaller or equal to 60, or bigger or equal to 69, then grade = D (which does not make sense)

5.) If the score is smaller or equal to 0, or bigger or equal to 59, then grade = F (which does not make sense)

If you enter this algorithm into a programming language and provide it with sample scores, only scores from 90 to 100 returns a grade.]]>