First time using void functions. Apologies again for the noobish thread.
I have a few questions on this problem.
1) Since the variables miles, gallons and milesPerGallon are used in both main and void, do I need to initialize them in each place? Or if they're initialized in main do I need to initialize them in void as well?
2) I'm not passing any arguments to the void, but rather expecting void to return two values to main. How do I set up the void prototype and the actual function call?
The professor wants us to fill in the prototype and documentation, fill in the code to invoke to void function, and fill in the void function heading, documentation, and actual prompts and read-ins of miles and gallons.
#include <iostream>
#include <iomanip>
using namespace std;
void GetMnG (float, float);
// This function asks user to input two real numbers, miles and gallons. it then calculates milesPerGallon and displays it to the page
int main ()
{
float miles = 0;
float gallons = 0;
float milesPerGallon = 0;
void GetMnG ();
cout << fixed << showpoint;
cout << setw(10) << miles
<< setw(10) << gallons
<< setw(10) << milesPerGallon << endl;
return 0;
}
//*****************************************************
void GetMnG ()
{
// Precondition: This function requires two real number inputs, miles and gallons
// Post Condition: This function feeds back the two numbers to main, which calculates and displays miles ped gallon
float miles = 0;
float gallons = 0;
float milesPerGallon = 0;
cout << "Input miles as a real number and enter" << endl;
cin >> miles;
cout << "Input gallons as a real number and enter" << endl;
cin >> gallons;
milesPerGallon = miles / gallons;
}