#include <iostream>using namespace std;bool Incrementa(char numero[10]);int main(){ char numero[10]; bool retu; cout << "Introduce un numero de 10 digitos max. Se le incrementara :)" << endl << endl; cout << "Numero a introducir: "; cin >> numero[10]; retu = Incrementa(numero[10]); if (!retu) { system("cls"); cout << "No ha insertado solo numeros :(" << endl << endl << endl; system("pause");} else { system("cls"); cout << "Su numero incrementado es: " << numero << endl << endl; system("pause"); return 0;}bool Incrementa(char numero[10]) { int i; int bucle; for (bucle=0;bucle<10;bucle++){ if (numero[bucle] != i) return false; } numero++; return true;}
char hola=a;if (char hola!=int)...
cin >> numero[10]; retu = Incrementa(numero[10]);
cin >> numero; retu = Incrementa(numero);
#include <iostream>#include <cstdlib>#include <ctype.h>using namespace std;bool Incrementa(char numero[10]);int main(){ char numero[10]; bool retu; cout << "Introduce un numero de 10 digitos max. Se le incrementara :)" << endl << endl; cout << "Numero a introducir: "; cin >> numero; retu = Incrementa(numero); if (!retu) { system("cls"); cout << "No ha insertado solo numeros :(" << endl << endl << endl; system("pause");} else { system("cls"); cout << "Su numero incrementado es: " << numero << endl << endl; system("pause");} return 0;}bool Incrementa(char numero[10]) { int bucle; int numconv; for (bucle=0;bucle<10;bucle++) if (isalpha(numero[bucle])) return false; numconv = atoi(numero); numconv++; itoa(numconv,numero,10); return true;}
Buff, ahora me encuentro con otra dificultad... Y esta vez no es un problema de compilación, sino que creo que el problema es el if (isalpha())...
Por lo tanto, he deducido (puede que incorrectamente xdd), que el problema reside en los huecos char, que no tienen valor. Es decir, si declaro numero[10], y luego hago un cin >> numero, en el que introduzco 3 carácteres, ahí esta el problema.La pregunta es, ¿ como consigo solventar este problema?
Si necesitas usar chars, una solución es inicializar todo el array a cero, y cuando encuentres un caracter que sea igual a cero (sin comillas) es que has llegado al final.
int bucle;for (bucle=0;bucle<10;bucle++) numero[bucle]=0;
#include <iostream>#include <cstdlib>#include <ctype.h>using namespace std;bool Incrementa(char numero[10]);int main(){ char numero[10]; bool retu; int bucle; for (bucle=0;bucle<10;bucle++) numero[bucle]=0; cout << "Introduce un numero de 10 digitos max. Se le incrementara :)" << endl << endl; cout << "Numero a introducir: "; cin >> numero; retu = Incrementa(numero); if (!retu) { system("cls"); cout << "No ha insertado solo numeros :(" << endl << endl << endl; system("pause");} else { system("cls"); cout << "Su numero incrementado es: " << numero << endl << endl; system("pause");} return 0;}bool Incrementa(char numero[10]) { int bucle; int numconv; for (bucle=0;bucle<10;bucle++) if (isalpha(numero[bucle])) return false; numconv = atoi(numero); numconv++; itoa(numconv,numero,10); return true;}