// Points assigned to each letter of the alphabet int POINTS[] = { 1 , 3 , 3 , 2 , 1 , 4 , 2 , 4 , 1 , 8 , 5 , 1 , 3 , 1 , 1 , 3 , 10 , 1 , 1 , 1 , 1 , 4 , 4 , 8 , 4 , 10 }; int compute_score( string word); int main( void ) // Get input words from both players string word1 = get_string( " Player 1: " ); string word2 = get_string( " Player 2: " ); // Score both words int score1 = compute_score(word1); int score2 = compute_score(word2); // TODO: Print the winner if (score1>score2) printf( " Player 1 Wins!" ); else if (score1<score2) printf( " Player 2 Wins!" ); printf( " Tie!" ); int compute_score( string word); // TODO: Compute and return score for string int score = 0 ; for i ( int i = 0 ; i<strlen(word); i++) if (isupper(word[i])) score = score + POINTS[word[i]-65]; if (islower(word[i])) score = score + POINTS[word[i]-97]; return score; What I have tried:
i have tried adding the bracket in different places but nothing seems to happen
the error is ;
scrabble.c: 42 : 5 : error: expected identifier or ' (' for i ( int i = 0 ; i<strlen(word); i++) 1 error generated. make: *** [<builtin>: scrabble] Error 1 scrabble/ $
Quote:
scrabble.c:42:5: error: expected identifier or '('
for i ( int i =0; i<strlen(word); i++)
="" ^
1="" error="" generated.
make:="" ***="" [<builtin="">: scrabble] Error 1
scrabble/ $

You might want to look at that for statement more closely. Go lookup the for loop in C [ ^ ] and read it. Look at the format of the statement and what you did wrong is glarily obvious. First off, that's not C - or at least not entirely standard C - or C#. It could be C++ which does have the std::string type, but C doesn't.
So start off by working out which language that is, because that's really quite important!
Secondly, when it comes to syntax errors it's important to look at all the information - starting with "what line in my code is throwing up the error?".
And we don't have that info, and since that won't compile as C, C#, or even C++ using an online compiler and we have no idea what you are using we can;t help you fix the problem directly.
It's also important to note that you should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.
We all make mistakes.
And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!
So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors [ ^ ] - it should help you next time you get a compilation error!
Quote:
i had removed that i that time only when i posted this because i realised it
but now its
#for (int i = 0; i < strlen(word); i++)#
and still no clue i dont see any clear error here please help
If you had followed the link I gave you, it should have been pretty obvious at some point over the last month ...
Look at the whole function declaration that the for loop is part of, particularly the function definition line. What's wrong here:
int compute_score(string word); // TODO: Compute and return score for string int score = 0 ; for i ( int i = 0 ; i < strlen(word); i++) {Do you see the problem?
I do.
Hint: what does a semicolon do?
Honestly, you will get syntax errors all the time: you have wasted a month on a semicolon that you should be able to spot yourself! Follow the link, and think about error messages - they really are trying to help you. :D int compute_score(string word);needs to define (that is, implement) this function, not declare it. You've already declared it before main , so now it needs to be
int compute_score(string word) // your code }Assuming that this is C++, a string is an object, and two things that you should do whenever possible are
(a) pass an object parameter by reference , to avoid the overhead of creating a copy of it: string& word
(b) make a parameter const if a function doesn't change it: const string word
Both of those things apply here, so a better signature for this function is
int compute_score( const string& word) // your code }Also, strlen(word) isn't going to work: strlen is for C strings ( char* ), not C++ strings. You want word.size() instead.
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •