Array with both numbers and alphabet

Pages: 12
Take out that line 6. A loop is not proper there, line 5 has already removed the tile and false==false, always.

You need to test the state of tile before you update it. So line 4 is the place. Test. if

You have two things that you can do. Either you can remove a tile, or you have to quit the while(true) loop.
You can remove a tile if it is present.
1
2
3
4
5
6
7
8
if ( /*tile is present*/ )
{
  // update tile
}
else
{
  break;
}

What would be correct /*tile is present*/ ?
It is a condition.
Wait, we were using ternary operator in output loop. What was its syntax?
condition ? result1 : result2 

Can we use the same condition here? Yes.

And then not quite. You have the other branch that removes two tiles. They have to both be present. That needs a more complex condition; you need boolean and. If tile1 is present and tile2 is present.


As a side project write a loop at the end of the program that calculates score and then show the score.
@ keskiverto
I have manage to amend my codes according to your advise but now I am unable to find the total scores
Codes to calculate score
1
2
3
4
5
6
7
8
else 
	{
		for(int i=0;i<13;i++)
		  total=0;
		total+=tiles[13];
		cout<<"Total Score is :"<<total;
		break;
	}


the total score given is very huge
You have written:
1
2
3
4
5
6
for(int i=0;i<13;i++)
{
  total=0;
}

total += tiles[13];

That sets the total to 0 for 13 times. One time would be enough. Then you add the value of tiles[13] once to total.

The array tiles has 13 elements. tiles[13] is not within the array. It is one beyond. The value that tiles[13] returns is undefined.

We already have loops that look at each element. We do use Begin and End there, because we use only 12 elements.

What should the score be? Is it 1 per present tile, or should it be the tile number? You can use the ternary operator again, only this time you return number instead of character.
The score is the sum of tiles with the letter 'E'.
Sum as in count, or sum of the tile numbers? If you have only one tile remaining at the end, the "10E", is the score 1 or 10?
If that's the case the score have be shown as 10.
Oh well dead end time for submission
Last edited on
Can i see your full code?

Don't ask that. Seeing too much code leads to copy-paste "programming", which does not benefit anyone.
Topic archived. No new replies allowed.
Pages: 12