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
)
string
word1 = get_string(
"
Player 1: "
);
string
word2 = get_string(
"
Player 2: "
);
int
score1 = compute_score(word1);
int
score2 = compute_score(word2);
if
(score1>score2)
printf(
"
Player 1 Wins!"
);
else
if
(score1<score2)
printf(
"
Player 2 Wins!"
);
printf(
"
Tie!"
);
int
compute_score(
string
word);
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);