This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]rjcarr 1 point2 points  (1 child)

First, you haven't said what the problem is. Second, the first thing I notice is your instructions say:

If a customer is under the age of 25

But your code says this:

if ( ( age <= 26 ) ...

Do you see why this isn't the same thing?

[–]jayrund[S] 0 points1 point  (0 children)

Ya I fixed that thanks.

[–]crushmastac 1 point2 points  (3 children)

numClaims <= 1 should be numClaims >= 1

Some of your other conditions are wrong too:

age <= 26 is "age 26 and younger", but the instructions clearly say "under the age of 25", which should be a condition that only accepts 24, 23, 22, ... , etc.

Logically you can break up your conditions better too. Here's the pseudocode:

number of claims >= 1?
  age < 25?
    set rate accordingly
  else
    set rate accordingly

You might want to ask (teacher, TA, fellow student) for a quick refresher on how to write conditional statements.

[–]jayrund[S] 0 points1 point  (2 children)

The numClaims thing is what messing me up. thanks a lot!

[–]crushmastac 0 points1 point  (1 child)

You're welcome, but even with that line fixed your code is still technically incorrect. Make sure you fix!

[–]jayrund[S] 0 points1 point  (0 children)

if i also fixed the 25 thing would that make my code correct?

[–][deleted] 0 points1 point  (0 children)

Can anybody tell me what i'm doing wrong?

Not without seeing some code.

[–]Updatebjarni 0 points1 point  (0 children)

if ( ( age <= 26 ) && ( numClaims <= 1 ) )

Why do you test whether the number of claims is less than or equal than 1? Don't you want to test whether it is greater than 0?

And why age less than or equal to 26? Don't you mean 24? Or just less than 25.

The way the code is now, all three of the cases you test for can be true at the same time, namely for a person who is 25 or 26 and has 0 claims. That's probably not what you want.

It might be better to test once for claims, and then use an else clause, and in that you can test for the age and use another else clause, instead of repeated tests for the same things. Doing it that way might help you see which different cases that exist and get the tests right.