0

hey guys can sumone please help me by telling wat exactly is the syntax for a do while loop....for example if v want to to ask the user integers again and again till a condition is satisfied...plz help...thank u

this is wat i have ritten but the loop never continues

# include <iostream.h>

void main ()

{int a=0;
int b=0;
int c=a-b;

do
{
cout<<"enter two integers"<<endl;
cin>>a;
cin>>b;
a=a;
b=b;
}

while(c>0);
}

6
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by loneal
0

v want to to ask the user integers again and again till a condition is satisfied

this is wat i have ritten but the loop never continues

# include <iostream.h>

void main ()

{int a=0;
int b=0;
int c=a-b;

do
{
cout<<"enter two integers"<<endl;
cin>>a;
cin>>b;
a=a;
b=b;
}

while(c>0);
}

You can write:

# include <iostream.h>

void main ()

{int a=0;
int b=0;
int c=a-b;
char ans;
do
{
cout<<"enter two integers"<<endl;
cin>>a;
cin>>b;
a=a;
b=b;

cout<<"More?";
cin>>ans;
}while(ans == 'y' || ans == 'Y');
}

Cheers

0
a=a
b=b

Are you assigning varibles to themselves?

int a=0;
int b=0;
int c=a-b;

So after these lines, c is 0.

do
{
cout<<"enter two integers"<<endl;
cin>>a;
cin>>b;
a=a;
b=b;
}

while(c>0);

It goes through the loop once, doesn't change the value of c, checks (c>0) at the end of the loop but stops as the condition is not satisfied.

0

as u have puted condition ...
while(c>0);

over here C is always zero ..
so loop will only rotate one time ..
then it will come out

0

as u have puted condition ...
while(c>0);

over here C is always zero ..
so loop will only rotate one time ..
then it will come out

0

You need to put the line:
c = a - b;
before the end of your loop (right after "b = b;").

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.