Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Setting Boundaries on Input for Numbers (http://www.go4expert.com/forums/setting-boundaries-input-t25674/)

jpacosm 1May2011 00:23

Setting Boundaries on Input for Numbers
 
I already turned in this code, but was trying to figure out for myself:
Code:

  {
                //arcsine
                cout << "Enter a degree to calculate for arcsine: (Choice should be between -1 and 1.) ";
                        cin >>num1;
                result = asin (num1) * 180.00 / pi;
                if (num1 >= -1)
                {
                        cout << "    The arcsine of " << num1 << " comes  out to be " << result << " degrees." << endl;
                }
                else
                {
                        cout << "Your choice is uncomputable in this equation. \n";
                }
        }

I have it so there is an error if your input is greater than 1, but I cannot figure out how to do it to set if your input is lower than negative 1 at the same time- How do I set two boundaries at once?

xpi0t0s 2May2011 13:47

Re: Setting Boundaries on Input for Numbers
 
Use multiple tests, so if you want to check if an input number is odd and between 32 and 45:
Code:

if ((inputNum%1) && (inputNum>=32) && (inputNum<=45))
  printf("Valid!\n");



All times are GMT +5.5. The time now is 07:59.