OK, there are three types of ways you can send a parameter to a function, by value, by reference, and with a pointer. The last two are essentially the same except for the syntax. By value is simple, it's what you did. It copies the data and sends it to the function. By reference sends the memory location of the variable you sent. That way, the function can modify them. Pointers are a bit more difficult, do a search.
For reference parameters, put an amperstand (&) before the variable's name:
Code:
void swap(int &a, int&b);
When calling a function, you do not need to specify the data type or apply special operators to the parameters. Simply, place their names (this is true for by value and by reference):
Code:
int a=3, b=4;
swap(a,b);
BTW, you can do this instead of what you had:
Code:
float miles;
float hours;
float milesPerHour;
// ---------------------
float miles, hours, milesPerHour;
Be careful not to put your '/' beside your '*' because that makes a multi-line comment. Not good if you use notepad! (no syntax highlightning, you'll never know you did that)
Code:
#include <iostream>
#include <iomanip>
using namespace std;
float GetData (float &miles, float &hours, float &milesPerHour);
int main()
{
float miles;
float hours;
float milesPerHour;
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
GetData(miles, hours, milesPerHour);
milesPerHour = miles / hours;
cout << setw(10) << miles
<< setw(10) << hours
<< setw(10) << milesPerHour << endl;
return 0;
}
// *****************************************************
float GetData (float &miles, float &hours, float &milesPerHour)
{
cout<<"Please enter the amount of miles and hours.";
cout<< "Press the enter key after each entry."<<endl;
cin>>miles;
cin>>hours;
}