(Code is entering fail-state) How do I fix?

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!



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//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>
using namespace 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;
	}
	else if (y > x && y > z)
	{
		cin >> max;
	}
	else if (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 
Last edited on
1
2
3
4
5
6
int maxOf3(int a, int b, int c){
  int max=0;
  max = (a > b) ? a : b;
  max = (c > max) ? c : max;
  return max;
}

Last edited on
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.
I'm not sure where to begin
@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.
I updated the void function to take arguments by reference and also added where input can be taken into x, y, and z.

I still do not know how to calculate the max using CalcMax function or how to set up the format for the definition of ReadNums and CalcMax
Any help guys?
Topic archived. No new replies allowed.