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

Recommended Answers

All 2 Replies

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.

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...)

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.