HELP PLS!!!!!!!!!!!!

#include <iostream>
using namespace std;

float subfactorial (int n) { //valor fijo
int k; //índice
float suma; //acumulador
k = 0;
suma = 0;
while (k <= n){
suma = suma + (potencia (k) / float(factorial (k)));
k = k + 1;
}
return factorial(n) * suma;
}
int potencia (int x) { //x es una variable fija
if (x % 2 == 0) {
return 1;
}
else{
return -1;
}
}
int factorial (int y) { //valor fijo
if (y == 0){
return 1;
}
else{
return y * factorial (y - 1);
}
}
int main (){

//uso de la función
int numero;
cout << "Teclea un valor numérico" << endl;
cin >> numero;
cout << "El subfactorial de " << numero << " es " << subfactorial(numero) << endl;
return 0;
}

Please help us, we need to solve this problem ASAP, can you tell us what fails we had commited?
Last edited on
int factorial (int y) { //valor fijo
And,
int potencia (int x) {
You have to make prototype declarations of those two before you use them.

Like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;


int potencia (int x);
int factorial (int y);

float subfactorial (int n) { //valor fijo
int k; //índice
float suma; //acumulador
k = 0;
suma = 0;
while (k <= n){
suma = suma + (potencia (k) / float(factorial (k)));
k = k + 1;
}
return factorial(n) * suma;
}
int potencia (int x) { //x es una variable fija
if (x % 2 == 0) {
return 1;
}
else{
return -1;
}
}
int factorial (int y) { //valor fijo
if (y == 0){
return 1;
}
else{
return y * factorial (y - 1);
}
}
int main (){
int numero;
cout << "Teclea un valor numérico" << endl;
cin >> numero;
cout << "El subfactorial de" << numero << "es" << subfactorial(numero) << endl;
}


Because the first time you call those functions, they we're not declared yet and the program doesn't know what it is.
Last edited on
Thank you, guy.
I love you so much.
Topic archived. No new replies allowed.