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);
}

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

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.

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

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

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

This article has been dead for over six months. Start a new discussion instead.