Please help me!!!

Hi i just started programming in c++ and im a little confused as to why my program isn't running efficiently. The object of this assignment is the prompt the user for a THREE DIGIT NUMBER and then multiply each integer together (EX. 123, (1 * 2 * 3). I want to know why when i enter a value for "b" that is < 100 or > 1000, my cout message isn't running, it just kicks the user out of the program.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  // PART B
        int b, c, d, e;

        cout << "please enter a 3 digit number: " << endl;
        cin >> b;

        if (b < 100 && b > 1000)
        {
                        cout << "sorry but thats not the right number" << endl;

        }
        while (b >= 100 && b < 1000)
        {

                         c = b / 100;
                         d = (b / 10) % 10;
                         e = b % 10;

                        cout << (c * d * e) << endl;
                        return 0;
        }

        cout << endl;

return 0;
}

[/code]
The correct format is
if ((b < 100) && (b > 1000))

I don' t know what to expect with the format your using.
I suspect it simply fails due to logic
The correct format is
if ((b < 100) && (b > 1000))
Inner parentheses are completely redundand and this code will fail to work too.

@OP b < 100 && b > 1000 means b is less than 100 and greater than 1000 at the same time. Obviously it is always false.

You want if b is less than 100 or if b is greater than 1000 statement: if( B < 100 || b > 1000)
Thank you so much MiiNiPaa, your insight by using the || was great and totally turned my program around!!! and SamuelAdams your code did not run correctly, the parenthesis made no difference in the program outcome.
Topic archived. No new replies allowed.