CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Posts
    10

    getting and int to accept only 2 numbers

    how do i get and int. to accept only 2 numbers

  2. #2
    Join Date
    Sep 2002
    Location
    Philippines
    Posts
    197
    Tell us about your systems configuration first.
    Your platform and compiler.

  3. #3
    Join Date
    Sep 2002
    Location
    Philadelphia ***Epoch: Timeless***
    Posts
    560
    I'm not sure what you mean by this, but if you mean the user enters something like 3956 and you want the int to take 39, here's one way to do it:
    [code]
    cout<<"Enter an integer: ";
    int num;
    cin>>num;
    while(num>=100)
    {
    num/=10;
    }
    cout<<"The first two digits of your integer are: "<<num<<endl;
    SolarFlare

    Those who cling to life die and those who defy death live. -Sun Tzu

    cout << endl;
    return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured