Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help!! with number inputs & no letters....

BerreBerre Member Posts: 1
What i want to do is a function that checks if its only
numbers in a CIN.. And if there are some letters in it,
i want the program to print "no letters" or something like that..
And then jump back to the CIN... And when the correct
input is done, the prog countinues to next step...




Comments

  • umair85umair85 Member Posts: 3
    : What i want to do is a function that checks if its only
    : numbers in a CIN.. And if there are some letters in it,
    : i want the program to print "no letters" or something like that..
    : And then jump back to the CIN... And when the correct
    : input is done, the prog countinues to next step...
    :
    :
    :
    :
    : Ok Try this

    int cin(void)
    {
    int no;
    char sno[10];
    START:
    cin>>sno; //sno is string of nos
    int index=0;
    while(index!strlen(sno))
    {
    if(sno[index++]<0 && sno[index++] >9)
    {
    goto START;
    }
    }
    no=atoi(sno);
    return no;
    }
    }
    Which is a very simple program if any problem than never hasitate to asl ,
    thanks
  • Geeth AsokanGeeth Asokan Member Posts: 127
    : What i want to do is a function that checks if its only
    : numbers in a CIN.. And if there are some letters in it,
    : i want the program to print "no letters" or something like that..
    : And then jump back to the CIN... And when the correct
    : input is done, the prog countinues to next step...
    :
    :
    :
    :
    :

    Hi,

    You could use the function [b]isdigit()[/b] and it requires the header file [b]#include [/b].

    Try out this piece of code:

    [code]
    //Example reads in a character and checks to see if it is a digit

    // You need this header file in order to use 'isdigit()'
    #include
    #include

    int main()

    {

    char a_char;

    cin>>a_char;

    if(isdigit(a_char))

    cout<<"Is a digit!";

    else

    cout<<"Is not a digit!";


    return 0;
    }
    [/code]

    Hope this helps,
  • PeterTheMasterPeterTheMaster Member Posts: 636
    when will you learn that iostream.h doesnt exist any more and ctype is deprecated?

    : : What i want to do is a function that checks if its only
    : : numbers in a CIN.. And if there are some letters in it,
    : : i want the program to print "no letters" or something like that..
    : : And then jump back to the CIN... And when the correct
    : : input is done, the prog countinues to next step...
    : :
    : :
    : :
    : :
    : :
    :
    : Hi,
    :
    : You could use the function [b]isdigit()[/b] and it requires the header file [b]#include [/b].
    :
    : Try out this piece of code:
    :
    : [code]
    : //Example reads in a character and checks to see if it is a digit
    :
    : // You need this header file in order to use 'isdigit()'
    : #include
    : #include
    :
    : int main()
    :
    : {
    :
    : char a_char;
    :
    : cin>>a_char;
    :
    : if(isdigit(a_char))
    :
    : cout<<"Is a digit!";
    :
    : else
    :
    : cout<<"Is not a digit!";
    :
    :
    : return 0;
    : }
    : [/code]
    :
    : Hope this helps,
    :

  • Justin BibJustin Bib USAMember Posts: 0

    _____ < http://forcoder.org /> free video tutorials and ebooks about [ Go Visual Basic .NET Scratch Assembly Python PL/SQL C++ Java Delphi Ruby Visual Basic C Objective-C Perl C# Swift JavaScript PHP MATLAB R Julia Alice D VBScript Lua Bash Transact-SQL Logo ABAP Kotlin Hack ML Dart Scheme Prolog F# LabVIEW FoxPro Apex Lisp SAS COBOL Clojure Erlang Fortran Rust Awk Ada Scala Crystal ] _________

Sign In or Register to comment.