Thread: mad scrolling

  1. #1
    Unregistered
    Guest

    mad scrolling

    Hi folks,


    Every time a user inputs anything other than a number in my programs it goes into a mad scroll…..is there a way to stop this….so that they would get an error message if the input was not a number

    Thanks fer any help…..

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> is there a way to stop this

    Yes.


    What do you mean, not helpful! My answer gives as much information as your question!!!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, let me just say that I ALWAYS grab input as strings! That is just my preference, and I have no problem converting numerical strings into ints, floats, etc.

    That being said, you could adopt this approach and go further with the validation process.

    For instance, you could write a function which validates that a string is in fact all numbers:

    Code:
    int validate(char *input)
    {
    int len = strlen(input);
    
    int i;
    
    for( i = 0; i < len; i++)
    {
    if(!isdigit(input[i]))
    return 0;
    }
    
    return 1;
    }


    Then in main you could do:


    Code:
    int main()
    {
    
    char input[100];
    int num;
    
    
    do{
    
    clrscr();
    
    printf("Enter A Valid Number: \n\n");
    
    fgets(input, 100, stdin);
    
    if( !validate(input) )
    continue;
    
    break;
    
    }while(1);
    
    num = atoi(input);
    
    /// rest of program...
    Hope that helps!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Unregistered
    Guest

    Thx

    Thx for the help Sebastiani.............

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scrolling background?
    By Deo in forum Game Programming
    Replies: 6
    Last Post: 06-09-2005, 05:40 PM
  2. I, Robot -- It's a trick, and I'm mad.
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-15-2004, 01:57 PM
  3. Scrolling
    By PJYelton in forum Windows Programming
    Replies: 10
    Last Post: 03-24-2003, 10:04 AM
  4. Bitmap scrolling with scroll bars
    By solar3147 in forum Windows Programming
    Replies: 0
    Last Post: 03-17-2003, 02:39 AM
  5. Spam :mad:
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-22-2001, 10:43 PM