“3 Consecutive statement on a line must be separated bay “;”)

Why is Swift rejecting the ; after it tells me to insert it?

That error is usually a bit misleading. In my experience there's usually a different issue it can't easily diagnose, so it just gives that error.

Can you share some of the code you're seeing generate this error? We can't provide any better help without it.

2 Likes

Hi Isaac:

Good Sat. pm and thank you very much for responding. I greatly appreciate it.

For context, below is the assignment given to me. The text in red below is XCode's automated direction instructing me to use “;”. But it does NOT work. Either I am misinterpreting the automated directions, or something else is going on:

Exercise: Lottery Tickets

Your friend’s entrepreneurial spirit knows no bounds. Now your friend is running the town lottery.

By naming things and only setting a value once, it's easier to figure out the correct way of calculating something. Later, you can change the values and check the answers.

// Values you should edit

let totalTicketsSold = 1000

let ticketPrice = 100

let printingCosts = 0

Exercise

You’ve done enough work for free for your friend. In return for your help on this venture, your friend will give you a tenth of the profits. The jackpot is half of the total ticket sales money. Try changing the numbers above - tickets sold, ticket price, printing costs, or advertising costs - and see if you can get your cut up to 100 or more.

The calculations below are fixed, but you can change the results by changing the numbers above:

// Total takings

let totalTakings = ticketPrice * ticketsSold

let totalTicketsSold - 1000. Consecutive statements on a line must be separated by ';'

let ticketsSold = 100

// Jackpot

let jackpot = totalTakings / 2

// Expenses

let totalExpenses = printingCosts + advertising

// Profit

let profit = totalTakings - jackpot - totalExpenses

// Distribution

let programmersCut = profit / 10 // This is the answer you want to get > 100!

let friendsCut = profit - programmersCut

Thanks, Isaac.

Jeff

Did you mean to put `=` rather than `-`?

1 Like

I'm only allowed to manipulate the upper values and calculations.

So in the upper section under:

“ticketsPrice” - 100

The automated system is telling me below to do the following:

Consecutive statements on a line must be separated by ‘;'

When I put in:

;

Between:

ticketPrice

( ticket; Price )

It is now telling me:

"Cannot find 'Price' in scope”

Even though the price is stated:

= 100

Jeff

`let identifier` can only be followed by `= value` or `: Type`. But in the line I pointed out, the token after the identifier isn’t `=` or `:`, it’s `-`. So, the compiler concludes that the `-` must belong to a different statement, and instructs you to insert a semicolon before it. In reality, a semicolon isn’t the answer, because there’s still be no type or value.

4 Likes

Seems like there's an error in your exercise because the part you shouldn't change is syntactically incorrect. This confuses the compiler and its suggestion for fixing it is unhelpful. So let's do some detective work…

At first glance it looks like the problematic line should have a `=` instead of a `-`. That will create a new variable with the name `totalTiketsSold` and assign `1000` to it. But if you make that change, you'll notice that the compiler complains about a redeclaration of `totalTicketsSold` because a variable with that name was already defined above (under "values you should edit").

Given this, it's more likely the intention behind the problematic line was to declare a new variable with another name. If you add a name and an `=` like this, everything works:

``````let missingVariableName = totalTiketsSold - 1000
``````

And now your exercise works... or at least it compiles. Maybe you should ask the person who gave you this assignment about what this line should be doing.

3 Likes

I am unsure how to interpret the SWIFT notification of "Expected pattern". Is it negative? Positive? Neutral?