Version:0.9 StartHTML:0000000105 EndHTML:0000003296 StartFragment:0000000152 EndFragment:0000003262
/******************************************************/
/*************** Isidro Pastor Jorda ******************/
/******************************************************/
/****************** Telematica ************************/
/******************************************************/
/************* Practica 7 Ejercicio 3 *****************/
/******************************************************/


#include <iostream.h>
#include <stdlib.h>
#include <string>
#include <math.h>

int main()
{
    string frase;
    int i, longitud, numero;
    bool error;
    error = false;
    cout << " Programa para cambiar un string de numeros a un entero \n";
    cout << " Introduce el numero para el string: ";
    getline (cin, frase);
    longitud = frase.length();
    numero = 0;
    for (i=0; i < longitud;i++)
    {
        if ( int(frase[i]) < int ('A'))
           numero = numero + ((int(frase[i]) - int( '0' ))*pow(10,(longitud-1) -i));
        else
            error = true;

    }
    if ( numero < 0)  // si el numero excede el valor que puede almacenar un entero damos error en la conversion
        error = true;


    if (!error)
        cout << "\n El string en enteros es: " << numero  << endl << endl;
    else
        cout << "\n Se ha producido un error en la conversion \n";



    system("PAUSE");
    return 0;
}