Do...While question?
Jul 28, 2010 at 2:36pm Jul 28, 2010 at 2:36pm UTC
OK. I'm doing an exercise and i stumbled upon a problem.
Is it possible with Do...While to do a break point and instantly end the loop
Like When i write in 0 and 0, to end my loop rather then write calculation of the two zeros and then end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
using namespace std;
int main(){
float a,b;
do {
cout<<"First number: " ;
cin>>a;
cout<<"Second number: " ;
cin>>b;
cout<<a<<" + " <<b<<"= " <<a+b<<endl;
cout<<a<<" - " <<b<<"= " <<a-b<<endl;
cout<<a<<" * " <<b<<"= " <<a*b<<endl;
cout<<a<<" / " <<b<<"= " <<a/b<<endl;
}
while (a!=0 && b!=0);
return 0;
}
I know i can do this with If...Else but i was just wondering if i could do it this way.
Jul 28, 2010 at 2:52pm Jul 28, 2010 at 2:52pm UTC
you can get out of a loop using
break ;
so you could
1 2
if (a == 0 || b == 0)
break ;
Last edited on Jul 28, 2010 at 2:55pm Jul 28, 2010 at 2:55pm UTC
Topic archived. No new replies allowed.