C
C#3y ago
cgxlm

Embedded Statement cannot be a declaration

Hi, I'm new to C# and struggling with this error. I think that the Variable cant be used because its not in the brackets but how do i fix this. This is the code and its for homework we have to create a program to determine what type of triangle it is and what the area is
8 Replies
Thinker
Thinker3y ago
Add brackets around each of the three statements If you don't have brackets, then you can only have a single statement and which cannot be a variable declaration. I.e.
if (side1 == side2)
{
double area = ...;
// etc.
}
if (side1 == side2)
{
double area = ...;
// etc.
}
Pobiega
Pobiega3y ago
Declare area before the ifs
Thinker
Thinker3y ago
oh yeah that too
cgxlm
cgxlmOP3y ago
Ahh Ok I didnt think you needed brackets because it was a single line didnt realise it could be a declaration Should i delete the one before?
Pobiega
Pobiega3y ago
Missed that one. Then just skip all the sub-declarations Don't declare area twice in any execution
cgxlm
cgxlmOP3y ago
Ahh ok also how would I fix these errors
Pobiega
Pobiega3y ago
look at the end of this line
cgxlm
cgxlmOP3y ago
Ah I see thank you
Want results from more Discord servers?
Add your server