Why wont my while statement work?
I think i am doing everything correctly.....but obviously i am missing something, my while statement doesn't seem to ever get entered. Please help....
#include <iostream>
using namespace std;
void swap(int *aPtr, int *bPtr)
{
int holder=0;
holder=*aPtr;
*aPtr=*bPtr;
*bPtr=holder;
}
void instantiator(int *dPtr,int *xPtr,int *yPtr,int a)
{
*dPtr=a;
*xPtr=1;
*yPtr=0;
}
void cruncher(int *xPtr,int *dPtr, int *aPtr,int *yPtr,int *bPtr)
{
int x1=0,x2=1,y1=1,y2=0,r=0,q=0;
while(*bPtr>0)
{
开发者_JS百科 q=*aPtr/(*bPtr);
r=*aPtr%*bPtr;
*xPtr=x2-(q*x1);
*yPtr=y2-(q*y1);
*aPtr=*bPtr;
*bPtr=r;
x2=x1;
x1=*xPtr;
y2=y1;
y1=*xPtr;
cout<<q<<" "<<r<<" "<<*xPtr<<" "<<*yPtr<<" "<<*aPtr<<" "
<<*bPtr<<" "<<x2<<" "<<x1<<" "<<y2<<" "<<y1<<endl;
}
cout<<endl;
*dPtr=*aPtr;
*xPtr=x2;
*yPtr=y2;
}
int main() {
int a=4864,b=3458,d,*aPtr,*bPtr,*dPtr,x,*xPtr,y,*yPtr;
aPtr=&a;
bPtr=&b;
dPtr=&d;
xPtr=&x;
yPtr=&y;
if(b=0)
instantiator(dPtr,xPtr,yPtr,a);
if (a<b)
swap(aPtr,bPtr);
cruncher(xPtr,dPtr,aPtr,yPtr,bPtr);
cout<<d<<" "<<x<<" "<<y;
return 0;
}
The test in your while
loop is *bPtr > 0
, yet you set b
to 0
in main
(using if (b=0)
) and then pass a pointer to it as bPtr
. Try fixing the if
statement in main
and see if that changes the behavior.
if(b=0)
. =
is an assignment operation. You need to use ==
for comparison. Correct it to if(b==0)
精彩评论