0

Where is the mistake in this code??? the compiler is always giving me mistakes

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static int squerd(int x,int y=2); { int result; for (int i=0; i < y; i= i+1) { result *=x; } return result; } static void Main(string[] args) { //int xc = squerd (10); Console.Writeline(squerd (10)); } } }

15th Jun 2016, 9:40 AM
Abd Al-hake
Abd Al-hake - avatar
18 Antworten
+ 11
There can not be semicolon after static int squerd(int x, int y=2) You have to initialize result=1 because you are going to multiply. And in main there should be WriteLine(squerd(10)). Keep in mind that c# is case sensitive.
15th Jun 2016, 11:27 AM
Hardip Raj
Hardip Raj - avatar
+ 2
your output is always zero anyway
15th Jun 2016, 11:16 AM
Roman Kolychev
Roman Kolychev - avatar
+ 2
I appreciate your help and patience
15th Jun 2016, 11:33 AM
Abd Al-hake
Abd Al-hake - avatar
0
i think the variable result that you declared as an int, it's not even defined. try to declare and define it as a "0"(zero). int result=0;
15th Jun 2016, 10:38 AM
Marco Romanin
Marco Romanin - avatar
0
wil I'v tried what you said but it keeps telling me things about ''invalid token '{' and '*=' and somthings like this
15th Jun 2016, 11:08 AM
Abd Al-hake
Abd Al-hake - avatar
0
well thank you guys
15th Jun 2016, 11:10 AM
Abd Al-hake
Abd Al-hake - avatar
0
yeah the output is always zero 'cause you multiply for zero, but i think you miss some sintactics
15th Jun 2016, 11:18 AM
Marco Romanin
Marco Romanin - avatar
0
I'll accept zero as an output but still don't work at all and the compiler give me these wierd mistakes
15th Jun 2016, 11:25 AM
Abd Al-hake
Abd Al-hake - avatar
0
wait for me, i will try to rewrite it all to find the little but bastard mistake, i think it is about indentation or sintax error
15th Jun 2016, 11:28 AM
Marco Romanin
Marco Romanin - avatar
0
thanks guys it was just 2 semicolon shouldn't be where they were and here is the working code:
15th Jun 2016, 11:50 AM
Abd Al-hake
Abd Al-hake - avatar
0
fine!
15th Jun 2016, 12:53 PM
Marco Romanin
Marco Romanin - avatar
0
Abd al hak wach momkin lface dialak ana brit net3elem lbarmaja o brit chwiya dial lmosa3ada il a brit
16th Jun 2016, 12:43 AM
Ibrahim Brian
0
Ibrahim Brian بإمكانك تحكي عربي ﻷن فكرتك ما وصلتني مليح
16th Jun 2016, 1:25 AM
Abd Al-hake
Abd Al-hake - avatar
0
you should give the resault intialize when you declare it at first
19th Jun 2016, 6:43 AM
sajjad
sajjad - avatar
0
static int squerd(int x,int y=2); the semicolon at the end of the statement declaring or creating the function squerd is the culprit. Get rid of the semicolon and your code should run smoothly
29th Jun 2016, 9:45 PM
Philip Dush
- 1
int result; // not defined you suppose to write int result=0; otherwise it doesnt have any value
15th Jun 2016, 10:39 AM
Roman Kolychev
Roman Kolychev - avatar
- 2
class Program { static int squerd(int x,int y=2) { int i =0; if (i<y) { x *=x; i=i+1; } return x; } static void Main(string[] args) { Console.WriteLine(squerd (10)); } } }
15th Jun 2016, 11:51 AM
Abd Al-hake
Abd Al-hake - avatar
- 2
using system; using system. collections. Generic; using system.Linq; using system. text; using system. threading. tasks; namespace sololearn { class program { static int pow(int x,int y=2); { int result; for( int i =0;i <y;i++) { result*=x; } static void main(string[] args); } console.writeline pow(10); } } this is the correct one program for your question
19th Jun 2016, 4:18 PM
ramu lu
ramu lu - avatar