looped in loop


i have the following program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int a,b=100;
do
{
cin>>a;
cout<<endl;
b=b-a;
cout<<b;

}
while(b>=0);
{
cout<<"0";
}


}

but my problem is that i am trying to get output as "0" as i get my b zero or less than it.........

thanks in advance....

progRammer007
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=100;
do
{
cin>>a;

b=b-a;
cout << b << endl;

} while(b>0); // Replaced b>=0 with b>0

cout<<"0";

}


That should do what you want.
Last edited on
this isn't solving my problem.......
what i really want that it should not show negative integers like -15 ......(like happens in a game when someone dies his hp is shown as 0 not a negative............)

You need to check it before you decrement it.

1
2
3
4
if(b-a<0)
    b=0;
else
    b-=a;
Topic archived. No new replies allowed.