Hey everyone, I'm having a hard time finishing this program. I'm brand new to programming and any help would be appreciated. This is what I have so far. I'm pretty sure I'll need to use an if-else statement to output the maximum, but not too sure of the rest of the code. Thanks, I really appreciate it!
//Purpose: Finish this program so taht it uses the following two functions:
// ReadNums - a void function called in main that uses cin to read three
// numbers that the user will type in, these three numbers will be
// In/Out parameters that main will then pass to the next function
// CalcMax - an int single value returning function that will determine
// the maximum of the three numbers.
#include <iostream>
usingnamespace std;
//Function declarations (prototypes) for ReadNums and CalcMax go here
void ReadNums(int& x, int& y, int& z);
int Calcmax(int max);
int main()
{
int x=0;
int y=0;
int z=0;
int max;
//Read in the three numbers using the ReadNums function
ReadNums(x, y, z);
//Calculate the max using the CalcMax value returning function
if (x > y && x > z)
{
cin >> max;
}
elseif (y > x && y > z)
{
cin >> max;
}
elseif (z > x && z > y)
{
cin >> max;
}
//Print the maximum
cout << "The maximum value of the three numbers you entered is " << max << endl;
return 0;
}
//ReadNums function definition goes here
//The function will prompt the user to enter three numbers, read the
//numbers and then pass those three numbers back to main.
void ReadNums(int& x, int& y, int& z)
{
cout << "Enter three numbers with a space in between each number and press Enter: ";
cin >> x >> y >> z;
}
//CalcMax function definition goes here
//It will return an int
Is that would I would use for CalcMax function definition?
Because the code has to be in the format that I listed above. I have to fill in the code where the comments are and leave everything else the same way.
@jmcdaniel10: Start with taking 3 numbers as input. Use cin>>x; to get the input. You will have to change the ReadNums function to take arguments by reference. A good reference on how to pass values by reference. http://www.cplusplus.com/doc/tutorial/functions/
Once you have the input in x, y, and z, you could then pass these to Calcmax function.