0

i am trying to do a program but i have two error and i don't know what they mean. can someone please help me.

this is the program

#include "stdafx.h"
#include <iostream>
using namespace std;



int S1(int x, int& y);
int S2(int& m, int n);

int main()
{
	int a = 2, b = 2, c =2;
	

	cout << "In main, " << endl
		 << "a = " << a << endl
		 << "b = " << b << endl<<endl;
		 

	a = S1(b, c);

	cout << "In main, " << endl
		 << "a = " << a << endl
		 << "b = " << b << endl;
		
	cout << endl << endl;
	return(0);
}
int S1(int& x, int& y)
{
	int t = S2(x,y);
		x = y;
		y = t;

	

	cout << "In S1, " << endl
		 << "t = " << t << endl
		 << "x = " << x << endl 
		 << "y = " << y <<endl<< endl;

	return(t * 3);
}
int S2(int& m, int n)
{
	int r=6;
	n=m;
	m++;

	cout << "In S2, " << endl
		 << "m = " << m << endl
		 << "n = " << n << endl 
		 << "r = " << r << endl<< endl;

	
	return(n + 1);
}

and these are the error messages

hwassinment error LNK2019: unresolved external symbol "int __cdecl S1
(ihwassinment fatal error LNK1120:
(int,int &)" (?S1@@YAHHAAH@Z) referenced in function _main

hwassinment fatal error LNK1120: 1 unresolved externals

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by 1o0oBhP
0

You're declaring a function int S1(int, int&) but defining it as int S1(int&, int&).
The linker can't find the function it expects to find (S1(int, int&) ) anywhere and throws a fit.

0

a = S1(b, c); --> c is an int, the parameter is an int&

make a pointer and pass it:

int *c_pointer = &c;
a = S1(b, c_pointer);


- S1 has also been re-defined twice differently both times (thats the linked error)
- S2(x, y) should be S2(&x, y) (i think...)

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.