a little help...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
  int a,b;
  b=10;
  for(a=3;b<3;b--) {
    cout << "Enter b:";
    cin >> b;

  }

  cout << "YEAAAAAAA";

  return 0;
}


Why doesn't this work? ,I'm trying to write a number and then if it is lower than 3 it will display yeeaa... but instead it just displays yeaaa...
Your loop body will only execute when b<3. Since that's never true, it will obviously never execute.
I see it now... thanks, but when I change that and enter 4 it displays yeaaa but it shouldn't,why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
  int a,b;
  b=10;
  for(a=3;b>3;b--) {
    cout << "Enter b:";
    cin >> b;

  }

  cout << "YEAAAAAAA";

  return 0;
}
because it has exited the loop as b is no longer bigger than 3 it is the same.

you entered 4
4 is bigger than 3 so b--(or b-1)
b Is now 3
3 is not bigger than 3
loop exits

displays yea
also what are you using int a for?
Topic archived. No new replies allowed.