I was trying to program a prime number detector, pretty close to success.
Here is my code, along with the error by the compiler, which I can't figure what it means.
Compilation error (line 6, col 3): } expected
Compilation error (line 12, col 3): Invalid token 'while' in class, struct, or interface member declaration
Compilation error (line 14, col 4): Method must have a return type
Compilation error (line 17, col 4): Invalid token 'if' in class, struct, or interface member declaration
Compilation error (line 17, col 10): Invalid token '.' in class, struct, or interface member declaration
Compilation error (line 17, col 11): Method must have a return type
Compilation error (line 17, col 25): Identifier expected
Compilation error (line 17, col 38): Invalid token ')' in class, struct, or interface member declaration
Compilation error (line 20, col 5): Invalid token 'if' in class, struct, or interface member declaration
Compilation error (line 20, col 10): Invalid token '==' in class, struct, or interface member declaration
Compilation error (line 21, col 14): Invalid token '=' in class, struct, or interface member declaration
Compilation error (line 23, col 5): A namespace cannot directly contain members such as fields or methods
Compilation error (line 40, col 4): Type or namespace definition, or end-of-file expected
Debugging is the part which bothers me the most. I tried so hard finding what's wrong in my code but couldn't find one. Maybe I was too tired?
Anyway, many thanks for replying.
Here is my code, along with the error by the compiler, which I can't figure what it means.
C#:
using System;
public class Program
{
public static void Main()
{
string Input(){
string input = Console.ReadLine();
return input;
}
while(true){
bool isPrime = true;
Input();
int value;
if(int.TryParse(Input(), out value)){
long x = Convert.ToInt64(Input());
if(x == 2 ){
isPrime = true;
}
else if(x % 2 == 0){
isPrime = false;
}
else{
for(int k = 3; k < x; k += 2){
if(x % k == 0){
isPrime = false;
}
}
}
if(isPrime == true){
Console.WriteLine(Input() + " is prime");
}
else{
Console.WriteLine(Input() + " is not prime");
}
}
else{
Console.WriteLine("Please enter a valid integer");
}
}
}
}
Compilation error (line 6, col 3): } expected
Compilation error (line 12, col 3): Invalid token 'while' in class, struct, or interface member declaration
Compilation error (line 14, col 4): Method must have a return type
Compilation error (line 17, col 4): Invalid token 'if' in class, struct, or interface member declaration
Compilation error (line 17, col 10): Invalid token '.' in class, struct, or interface member declaration
Compilation error (line 17, col 11): Method must have a return type
Compilation error (line 17, col 25): Identifier expected
Compilation error (line 17, col 38): Invalid token ')' in class, struct, or interface member declaration
Compilation error (line 20, col 5): Invalid token 'if' in class, struct, or interface member declaration
Compilation error (line 20, col 10): Invalid token '==' in class, struct, or interface member declaration
Compilation error (line 21, col 14): Invalid token '=' in class, struct, or interface member declaration
Compilation error (line 23, col 5): A namespace cannot directly contain members such as fields or methods
Compilation error (line 40, col 4): Type or namespace definition, or end-of-file expected
Debugging is the part which bothers me the most. I tried so hard finding what's wrong in my code but couldn't find one. Maybe I was too tired?
Anyway, many thanks for replying.