-5
I’m doing the following program on C#:
Create an abstract class named "Combinatorial Analysis", responsible for specifying, in addition to the factorial calculation of a number, the methods due to Calculation of Permutations, Arrangements and Combinations of elements[...]
I need to make a class called Combinatorial Analysis in which I must perform the factorial calculation of a number that will be typed by the user in the main program.
I know how to make the factorial, but within a class, you’re not even free to do any kind of equal accounts on Static void Main.
That’s the way I’ve done it:
public abstract class AnaliseCombinatoria
{
static int Fatorial(int numero)
{
for(int i = 0; numero <= 1; i--)
{
return numero * (numero - 1);
}
}
}
You are giving an error in the variable "Factorial" saying: "Combinatorial analysis.Factorial(int)": not all code paths return a value
How do you make calculations within a class?
David, your question is vague. Could you show us what you already have and illustrate what you want to do?
– cpll
Buddy, your mistake is not about being in another class or not. 1 - You said you are not free to do the calculations in a class as you are free in
main
. But themain
is within a class too, which you probably named afterInicializador
or something like. 2 - Your error is simple to solve.static int Fatorial(int numero) {
 
 for (int i = 0; numero <= 1; i--) {
 
 return numero * (numero - 1);
 }
 
 return numero; // É só por esse return aqui que a IDE vai parar de reclamar
 }
– Richard Willian
Sometimes, when a red or yellow line appears, under your code, you press
Ctrl + 1
(If you are in Eclipse) it will give you some options on how to solve a particular problem. In your case, the IDE is complaining that your method is not returning a value in all possible cases, because, if your variablenumero
forMaior ou igual a 1
, will do nothing inFOR
and his method would return nothing, and is bound to return something.– Richard Willian
First, you are giving a Return inside the loop for or else the first calculation will stop because the Return inside a loop or any runline terminates the command, remove the Return out of the loop.
– Marcos Brinner