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)); } } }
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.
+ 2
your output is always zero anyway
+ 2
I appreciate your help and patience
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;
0
wil I'v tried what you said but it keeps telling me things about ''invalid token '{' and '*=' and somthings like this
0
well thank you guys
0
yeah the output is always zero 'cause you multiply for zero, but i think you miss some sintactics
0
I'll accept zero as an output but still don't work at all and the compiler give me these wierd mistakes
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
0
thanks guys it was just 2 semicolon shouldn't be where they were and here is the working code:
0
fine!
0
Abd al hak wach momkin lface dialak ana brit net3elem lbarmaja o brit chwiya dial lmosa3ada il a brit
0
Ibrahim Brian بإمكانك تحكي عربي ﻷن فكرتك ما وصلتني مليح
0
you should give the resault intialize when you declare it at first
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
- 1
int result; // not defined
you suppose to write
int result=0;
otherwise it doesnt have any value
- 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));
}
}
}
- 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