1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Setting Boundaries on Input for Numbers

Discussion in 'C++' started by jpacosm, Apr 30, 2011.

  1. jpacosm

    jpacosm New Member

    Joined:
    Apr 30, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
    Last edited by a moderator: May 1, 2011
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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");
    
     

Share This Page