Hello everyone. I have a problem with referencing int functions. My function has three arguments so my question is, can functions with arguments be referenced at all, I cant seem to find this on the internet and referencing seems to work fine if it is with a function with no parameters.
int ThreeIntegerAddition(int first, int second, int third){return first + second + third;}
int& ThreeIntegerAddition;
int main(){
cout << "Please enter three numbers to add them up" << endl;
cin >> first;
cin >> second;
cin >> third;
cout << ThreeIntegerAddition() << endl;
}
This program isn't really meant for any practical application and is a bit stupid, but it was just something I chose to try to apply referencing with functions.
Im sorry the reason i put (1) (2) and (3) was because I made a new program out of the code which didnt use referencing, however I changed it back so that I could use it to display the problem I was having, the code is meant to be without the value, so:
What do you mean "Shall not be compilled"...Why are you using future tense...I dont understand
It is required a little to understand what I am saying about. Just try to compile your code. Why are you showing a code that you even did not compile yourself?!
Why am I showing a code which I did not compile myself?.....because it wont compile! Thats the issue which I'm having, hence why I am asking for help on this forum.
// Adding.cpp : main project file.
#include <iostream>
//#include <cmath> // Not needed. You're not using high math
// #include <string> // Not needed. You're not using strings
usingnamespace std;
// int first, second, third; // Try not using global variables
int ThreeIntegerAddition(int one, int two, int three)
{
// These, int one, int two, int three, take the values of the variables being passed
return one + two + three;
}
//int& ThreeIntegerAddition; // Not needed
int main()
{
int first, second, third;
cout << "Please enter three numbers to add them up" << endl;
cin >> first;
cin >> second;
cin >> third;
cout << ThreeIntegerAddition(first, second, third) << endl;
// You needed to send the variables to the function
return 0;
}
Except you are passing a copy instead of reference change 11 to void ThreeIntegerAddition( int &one , int &two , int &three )
Then remove the return statement