If statement discussion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • casey2007
    New Member
    • Mar 2007
    • 4

    #1

    If statement discussion

    Hey I was wondering about how you go about designing a IF statement that will use a range of values and if it was out of those range of values, e.g if it was a negative or if it exceeded a certain number, how do i go about creating a IF statement that follows these guidelines.

    I have created a IF statement but it only accounts for 1 variable/value at a time and I would like to created a range of variables to be used e.g. 0 - 23953.

    if (Download == 1)
    {
    cout << "1 megabytes downloaded" << endl;
    }
    else if (Download == 2)
    {
    cout << "2 megabytes downloaded" << endl;
    }
    else if (Download == 3)
    {
    cout << "3 megabytes downloaded" << endl;

    I would like to make it so it goes from (1 - 10000)
    If it is below 0 it poses a Error and the program closes or If it exceeds 10000 it poses a error and closes, and if any value is entered between 0 - 10000 it displays it on the screen perfectly without creating an error as the appropriate values are used.

    Thanks Casey
  • casey2007
    New Member
    • Mar 2007
    • 4

    #2
    Oh sorry I didnt post what compiler im using:

    Im using Microsoft Visual Studios.NET 2003 C++

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      So basically, you want to see if Download is between 0 and 10000 (for example) instead of 1, or 2, or 3...etc.

      An if... statement requires a boolean expression. == is just one of several operators that evaluates to a boolean value. Others include < (less than), > (greater than), != (does not equal), <= (less than or equal to), and >= (greater than or equal to).

      Using these, you can check if Download is greater than 0. Now, this will give you an infinite amount of values, so you will have to also check if Download is less than 10000. To combine two or more boolean 'checks', you can use && (and) or || (or). Each is an operator that works on two boolean values - and requires both values to be true, and or requires only one value to be true.

      Can you write the if...statements for what you need now?

      Comment

      • casey2007
        New Member
        • Mar 2007
        • 4

        #4
        Originally posted by Ganon11
        So basically, you want to see if Download is between 0 and 10000 (for example) instead of 1, or 2, or 3...etc.

        An if... statement requires a boolean expression. == is just one of several operators that evaluates to a boolean value. Others include < (less than), > (greater than), != (does not equal), <= (less than or equal to), and >= (greater than or equal to).

        Using these, you can check if Download is greater than 0. Now, this will give you an infinite amount of values, so you will have to also check if Download is less than 10000. To combine two or more boolean 'checks', you can use && (and) or || (or). Each is an operator that works on two boolean values - and requires both values to be true, and or requires only one value to be true.

        Can you write the if...statements for what you need now?
        Yes thankyou very much Ganon11 for your helpful information :).
        Casey

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Glad to help out!

          Comment

          Working...