
Error al llamado de función
Publicado por Flores (1 intervención) el 10/08/2022 05:14:58
Tengo un problema al llamar la función en el codigo, ¿podrían ayudarme?
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
void esperar(double t);
void ingresardatos(float &n1);
float paroimpar(float &a);
int numeroprimo(const int &a);
int capicua(int w);
float capicua2(float r);
int main() {
int num;
int op;
float respuesta;
do {
cout << "----------------- Menu de opciones ----------------- \n";
cout << "1: Verificar si un número es par o impar \n";
cout << "2: Verificar si un número si es primo \n";
cout << "3: Verificar si un numero es capicua (funcion iterativa) \n";
cout << "4: Verificar si un numero es capicua (función recursiva) \n" ;
cout << "5: Salir del programa \n";
cin >> op;
if (op>5) {
cout << "Error! \n";
cout << "Opcion no valida \n";
esperar(3*1000);
}
if (op==5){
cout<<"Adios\t";
}
switch (op) {
case 1:
cout << "Operacion numero par o impar \n";
// llamado de la funcion numero par o impar
ingresardatos(num);
cout << "El numero " << paroimpar(num) << endl;
esperar(2*1000);
break;
case 2:
cout << "Operacion numero primo \n";
ingresardatos(num);
cout << "El numero " << numeroprimo(num) << endl;
esperar(2*1000);
break;
case 3:
cout << "Verificar si un numero es capicua (función iterativa) \n";
cout << "..." << capicua(num) << endl;
esperar(2*1000);
break;
case 4:
cout << "Verificar si un numero es capicua (función recursiva)" << endl;
cout << "..." << capicua2(num) << endl;
break;
}
} while ((op!=5));
esperar(2*1000);
return 0;
}
void ingresardatos(float &n1){
cout<<"Ingrese un numero \t";
cin>>n1;
}
float paroimpar(float &a) {
int respuesta;
if (a%2==0) {
cout << "es par" << endl;
} else {
cout << "es impar" << endl;
}
return respuesta;
}
int numeroprimo(int &a) {
float contador;
float x;
float respuesta;
x = 1;
contador = 0;
while (x<=a) {
if (a%x==0) {
contador = contador+1;
}
x = x+1;
}
if (contador==2) {
cout << "es primo" << endl;
} else {
cout << "no es primo" << endl;
}
return respuesta;
}
int capicua(int w) {
int aux;
int nf;
int cp;
cout << "Ingrese el numero de tres digitos" << endl;
cin >> w;
aux = w;
nf = 0;
while (aux>0) {
nf = nf+aux%10;
nf = nf*10;
aux = int(aux/10);
}
nf = nf/10;
if (w==nf) {
cout << "el numero es capicua" << endl;
} else {
cout << "No es capicua" << endl;
}
return cp;
}
float capicua2(float r) {
float digitos;
float rev;
float tmp;
float cpr;
cout << "Ingrese un numero de 3 cifras" << endl;
cin >> r;
// Hacemos un número 10^(numero de cifras-1) con esto alreves determinará el
// número de cifras que tiene el número dado.
tmp = r;
while (tmp>=10) {
tmp = tmp/10;
digitos = digitos*10;
}
rev = digitos;
rev = r;
// Capicúa o no ?
if (rev==r) {
cout << "el numero es capicua" << endl;
} else {
cout << "NO es capicua" << endl;
}
return cpr;
}
void esperar(double t) {
clock_t t0 = clock();
double e = 0;
do {
e = 1000*double(clock()-t0)/CLOCKS_PER_SEC;
} while (e<t);
}
Valora esta pregunta


0