Ask coding questions

← Back to all posts
Can someone fix my error?
LienDo (1)

using System;

class Arithmetric {
static public int Add (int a, int b, int c){

 int sum = a + b + c;
 Console.WriteLine (a + "+" + b + "+" + c + "=" + sum);
 return sum;

}
static public int Subtract (int a, int b, int c){

 int difference = a - b - c;
 Console.WriteLine (a + "-" + b + "-" + c + "=" + difference);
 return difference;

}
static public int Multiply (int a, int b, int c){

 int product = a * b * c;
 Console.WriteLine (a + "*" + b + "*" + c + "=" + product);
 return product;

}
static public int Divide (int a, int b, int c){

 int quotient = a / b / c;
 Console.WriteLine (a + "/" + b + "/" + c + "=" + quotient);
 return quotient;

}
static void Main (string[] args) {
Arithmetric object = new Arithmetric();
object.Add(10, 15, 20);
object.Subtract(100,20,16);
object.Multiply(34, 15, 27);
object.Divide(100, 10, 15);
}
}

Error:
main.cs(29,16): error cs1525: Unexpected symbol 'object'
main.cs(29,23): error cs1525: Unexpected symbol '='
Compilation failed: 2 error(s), 0 warning
compiler exit status 1

Commentshotnewtop
CodeLongAndPros (1472)

Please link to the relevant repl.

LienDo (1)

@CodeLongAndPros Your is working. Can you explain how did you fix it?

CodeLongAndPros (1472)

@LienDo You had to remove all of the static keywords.

You had to append a } at the EOF

You had to rename object to ar

LienDo (1)

@CodeLongAndPros Thank you so much for helping! I got it now

CodeLongAndPros (1472)

@LienDo Glad to help.

Please mark it as the answer if it helped

LienDo (1)

@CodeLongAndPros hi. I tried to create 2 subclass for the method. But I can't fix my error. Can you help me one more time? Here is the link:
https://repl.it/@LienDo/LuxuriousWonderfulApplicationprogrammer

CodeLongAndPros (1472)

@LienDo You have to append } at the end.

LienDo (1)

@CodeLongAndPros yes. I have tried to append } but it gets more errors.

CodeLongAndPros (1472)

@LienDo Its because ar1 doesn’t have the functions Add, Subtract…

CodeLongAndPros (1472)

@LienDo This is a bit more confusing. You should isolate your classes.
Yours is like this MainClass => Arithmetic => check => public static void main()

I think you should just refactor your code a bit more, and see if you don't catch the problem.

LienDo (1)

@CodeLongAndPros yes, I did my code based on the template that the teacher gave me. But I don't know why it's not working.