So in the tutorial section for functions most of the values passed between functions are constant, I want to make a program that ask the user for two values to add and use another function to add them together. No matter what numbers I enter I get 2 as the result. What am I doing wrong?
# include <iostream>
usingnamespace std;
/*This program ask the user for two varables (a and b) to add together*/
int addition (int c, int a, int b)
//Function used for addition
{
c=a+b;
return c=a+b; //returns the result for addition
}
int main ()
{
int a;
int b;
int result;
cout << "Please enter in your first number" << endl;
cin >> a ;
cout << "Please enter in your second number" << endl;
cin >> b;
int addition (result); // calls addition function
cout << "Your result is" << a << "+" << b << "=" << addition <<endl;
system ("Pause");
}
int addition(int a, int b) // Your 'c' variable isn't needed here
{
return a + b;
}
int main()
{
int a, b, result;
// ... (prompt for a and b) ...
result = addition(a, b); // Use the return value by assigning it to a variable
cout << "Your result is" << a << "+" << b << "=" << result << endl;
}