The point of passing a value by reference is so that you can modify it within the function and the changes will be saved to the variables that were passed to the function.
Try compiling and running this, and notice how the function that takes references (with the '&') actually changes the variables passed to it, while the other one doesn't. Also noticed that the variable in main() doesn't have to have the same name as the one in the function, because they are two different variables.
Code:
#include <iostream>
using namespace std;
void ChangeData(int&, int&, int&);
void UseData(int, int, int);
int main()
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
cout << "Before calling ChangeData: ";
cout << num1 << ", " << num2 << ", " << num3 << endl;
ChangeData(num1, num2, num3);
cout << "After calling ChangeData: ";
cout << num1 << ", " << num2 << ", " << num3 << endl;
UseData(num1, num2, num3);
cout << "After calling UseData: ";
cout << num1 << ", " << num2 << ", " << num3 << endl;
return 0;
}
void ChangeData(int& one, int& two, int& three)
{
one = 1;
two = 2;
three = 3;
}
void UseData(int one, int two, int three)
{
one = 16;
two = 17;
three = 18;
}
So, hopefully that helps you understand that your calculate function isn't changing the passed in values, it is only using them to calculate the total. Other notes:
1. Make sure the function prototype (above main()) matches the function definition (where you actually write the function). In your posted code, you have:
void get_input(char, int&, float&);
but in your definition you have
void get_input(char& product, int& quantity, float& price)
Make sure you add the '&' to the prototype at the top. The same goes for the calculate function. If the prototype does not have '&', the definition shouldn't either.
2. You have a product name stored as a char. That holds a single character, not a string. I'd suggest when you test your method only typing in a single character as the product name for now (e.g. 'L'). Then, once you have everything else working you can figure out how to get an entire string instead of a single char.
3. Your calculate function calculates the total, but the total is never output. Either output the total in the function or save the return value when you call the function in main.