Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing reference errors 1

Status
Not open for further replies.

jwdcfdeveloper

Programmer
Mar 20, 2001
170
US
I am getting errors w/ my code concerning an undeclared parameter and a parse error.

Here's the code:

#include "iostream"
using namespace std;

int findgcd(int a, int b) {

int r,q,x0_old,y0_old,y1_old,gcd;
int x0 = 1;
int x1 = 0;
int y0 = 1;
int y1 = 0;

r = a mod b;

do {
q = (a-r)/b;
a = b;
b = r;
x0_old = x0;
y0_old - y0;
x0 = x1;
y0 = y1;
x1 = x0_old - (q*x1);
y1 = y1_old - (q*y1);
r = a mod b;
} while (r != 0);

gcd = b;
return(gcd);

}

int main()
{

int z;
z = findgcd(11,7);
cout << &quot;The GCD is: &quot; << z;
return 0;
}


Here are the primary errors:

12 c:\docume~1\jamesw~1\mydocu~1\csc309\prob2.cpp
`a' undeclared (first use this function)
12 c:\docume~1\jamesw~1\mydocu~1\csc309\prob2.cpp
parse error before `b'


I am not sure why 'a' is undeclared, and I assume the the second error is related to the first. Does anyone have any ideas about solving this one?
 
Use the correct syntax for &quot;mod&quot; which is &quot;mod(a,b)&quot;, i.e.
r = mod(a,b);
in stead for
r = a mod b;

The latter calls function a which is undeclared......

Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top