C++ Programming Blog

 
 
 
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <process.h>

int main()
{
    int flag = 0;
    char ch = NULL;
    char state = \'0\';
    char token[20] = {NULL};
    char stt[5][3] = {NULL, \'4\', \'5\',
            \'0\', \'1\', \'2\',
            \'1\', \'1\', \'2\',
            \'2\', \'3\', NULL,
            \'3\', \'3\', NULL};

    cout<<\"Input float data : \";
    cin>>token;

    for(int i=0; token[i] != NULL; i++)
    {
        if(isdigit(token[i]))
        {
            ch = \'4\';
        }
        else if (token[i] == \'.\')
        {
            ch = \'5\';
        }
        else
        {
            flag=1;
            printf(\"Invalide value\");
            break;
        }

        for(int j=1; j<3 && ch != stt[0][j]; j++);
        for(int k=1; k<5 && state != stt[k][0]; k++);
        state =stt[k][j];
        if(state==NULL)
        {
            flag=1;
            printf(\"Invalide value\");
            break;
        }
    }
    if(flag==0)
    {
        printf(\"Valide value\");
    }
    getch();
    return 0;
}