I have to ge t the result using call by reference. I'm receiving 4 errors???
from my understanding, I have 'declared' total before main. Quite frankly, I'm not getting why not declared it on display_output nonetheless??
and why total is still not being recognized??

Thanks in advance for the help!
eddy
____________________________________

//This program allows the user to enter 3 integers
//then computes their sum and outputs the result.

#include <iostream>
using namespace std;

 void get_input (int& num1, int& num2, int& num3);
 int  find_sum  (int& num1, int& num2, int& num3);
 void display_output(int& num1, int& num2, int& num3, int& total);

int main()
{

	int num1, num2, num3, sum, total;
	char answer;

// get input from user
	do 
	{
get_input (num1, num2, num3);

		sum= find_sum(num1, num2, num3);

display_output(num1, num2, num3, total);
	
		cout << "Do you want to continue? (Enter Yes or No)"<<endl;
		cin >> answer;
	}
	while (answer != 'n' && answer !='N');

	return 0;
}
 void get_input(int a, int b, int c)
 {
	cout << "Enter the first number" <<endl;
	cin >> a;
	cout << "Enter the second number" <<endl;
	cin >> b;
	cout << "Enter the third number" <<endl;
	cin >> c;
 }

 int find_sum  (int a, int b, int c)
 {	 
	return a+b+c;
 }

 void display_output(int a, int b, int c, int total)
 {
	 cout << "The sum of" << a << b << c << " is "
		  << total << endl;
 }

>> I'm receiving 4 errors
please post them.

my guess about the errors: The parameters on line 45 must match exactly line 6. Same with line 5 and 40.

You forgot to add the reference symbol in front of your variable names on lines 30, 40 and 45.

>> I'm receiving 4 errors
please post them.

my guess about the errors: The parameters on line 45 must match exactly line 6. Same with line 5 and 40.

Thanks for the input Ancient Dragon..I will work on that
here's the 4 errors that I keep getting, (hope that helps)

error LNK2001: unresolved external symbol "void __cdecl display_output(int &,int &,int &,int &)" (?display_output@@YAXAAH000@Z)

error LNK2001: unresolved external symbol "int __cdecl find_sum(int &,int &,int &)" (?find_sum@@YAHAAH00@Z)

error LNK2001: unresolved external symbol "void __cdecl get_input(int &,int &,int &)" (?get_input@@YAXAAH00@Z)

fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

4 error(s), 0 warning(s)

Those errors mean that you prototyped the functions using the reference operator, but the actual functions get the paramets by value, not by reference. The functions, even though they have the same name, are not the same. Fix the problem as already pointed out a couple times before.

Those errors mean that you prototyped the functions using the reference operator, but the actual functions get the paramets by value, not by reference. The functions, even though they have the same name, are not the same. Fix the problem as already pointed out a couple times before.

Thanks Guys..
I fixed the problem like mentioned..
line 11 kinda confused.. my confusion is this..
If I understand, the call by ref. I only need to call total when it passed by ref.
and not to identify total as an int in main. am i wrong??

(my stupidity on all the lines on call by reference)

ok so far so good, still working on it! I only have 1 error, 0 warnings
error C2065: 'total' : undeclared identifier


_______________________________________

//This program allows the user to enter 3 integers
//then computes their sum and outputs the result.

#include <iostream>
using namespace std;

 void get_input (int& num1, int& num2, int& num3);
 int  find_sum  (int& num1, int& num2, int& num3);
 void display_output(int& num1, int& num2, int& num3, int& total);

int main()
{

	int num1, num2, num3, sum;
	char answer, result;

// get input from user
	do 
	{
get_input (num1, num2, num3);

		sum= find_sum(num1, num2, num3);

display_output(num1, num2, num3, total);
	
		cout << "Do you want to continue? (Enter Yes or No)"<<endl;
		cin >> answer;
	}
	while (answer != 'n' && answer !='N');

	return 0;
}
 void get_input(int& a, int& b, int& c)
 {
	cout << "Enter the first number" <<endl;
	cin >> a;
	cout << "Enter the second number" <<endl;
	cin >> b;
	cout << "Enter the third number" <<endl;
	cin >> c;
 }

 int find_sum  (int& a, int& b, int& c)
 {	 
	return a+b+c;
 }

 void display_output(int& a, int& b, int& c, char result)
 {
	 cout << "The sum of" << a << b << c << " is "
		  << result << endl;
 }

>>am i wrong??
Yes, you are wrong. You ALWAYS have to declare variables before they can be used. And on line 24 total is no different. pass by reference means that the receiving function ( display_output in your program) will have direct access to the referenced variables which must be declared somewhere in your program. So if display_output changes the value of total then that change will be visible when display_output returns to its caller -- in your program main().

And in case you have not figured it out yourself by now, line 45 is incorrect. You forgot the last parameter -- total.

First, I'm not understanding why are you all being so weird here. There totally no of TOTAL Just refer to your code.

display_output(num1, num2, num3, sum);
void display_output(int& a, int& b, int& c, int& result)

And you might wanna declare result as integer too. That is all there is. No other errors.

>I have 'declared' total before main
You have never declared total before main(), you only declared the function. The proper declaration of it would be int total; where ever you want to declare it or with which ever scope.

First, I'm not understanding why are you all being so weird here. There totally no of TOTAL Just refer to your code.

Look who's calling the kettle black -- you can't write a sentence that makes any sense. :)

>you can't write a sentence that makes any sense.
Sorry for not being a scholar in English. >_>

Eddy518,
Logic-wise, it looks like you want to feed the result of find_sum() into the fourth parameter of display_output(). Get rid of 'total' altogether and say 'display_output(num1, num2, num3, sum). Some would just say 'display_output(num1, num2, num3, find_sum(num1, num2, num3))' but that is not much fun to look at or debug...

Change the char back to &total to match your decl.

>you can't write a sentence that makes any sense.
Sorry for not being a scholar in English. >_>

We don't expect you to be. Just write sentences that people can understand -- grammer doesn't have to be perfect, just understandable. I still have not figured it out

Special thanks to all the posters for ALL the input! I got it to work!!
I will continue to browse this GREAT forum for knowledge. In the meantime, I will be working on my next Programming Assignment. If I have any question, I will post them. Wish me Luck!

We don't expect you to be. Just write sentences that people can understand -- grammer doesn't have to be perfect, just understandable. I still have not figured it out

> There totally no of TOTAL Just refer to your code.

This is the part you were referring to, right? Well, I just went back a re-read it. LOL it surely is weird. I didn't realize so many typ-o's. Well, What I wanted to say was, There was no need to use "total". Just refer to the code below :

xD I got you'll more confused that the others ><

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.