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

to continue your loop
u should put your statement
c=a-b in the
do
{

}while(c>0);


block

int a,b,c;
a=b=c=0;
do
{
cout<<"Enter 2 numbers:";
cin>>a;
cin>>b;
c=a-b;
}while(c>0);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.