help

how do i write void arrange?

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
#include <iostream>
using namespace std;

void askValues(int &x,int &y,int &z);
void arrange();

int main(){
	
int x,y,z;

//The function below asks 3 numbers from the user
	askValues(x,y,z);

//The function below rearranges the values based on the 4th 
//argument. If the 4th argument is 1 sort the numbers from
//lowest to highest, if the 4th argument is 2, sort the
//numbers from highest to lowest
	arrange(x,y,z,1);
/*
//The function below displays the values of the 3 numbers
// and the string passed as the 4th argument. Refer to the 
// sample dialogues section below
 for the format
	dispValues(x,y,z, "lowest to highest: ");
	arrange(x,y,z,2);
	dispValues(x,y,z, "highest to lowest: ");
*/
return 0;
}

void askValues(int &x,int &y,int &z){
	cout << "Type 3 numbers: ";
	cin >> x >> y >> z;
}

void arrange(){
}
Try starting off like this...

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
#include <iostream>
using namespace std;
void askValues ( int x, int y, int z );
int main()
{
    askValues ( 1, 2, 1 );
    askValues ( 1, 2, 2 );
    askValues ( 1, 2, 4 );
    return 0;
}

void askValues ( int x, int y, int z )
{
    switch ( z )
    {
    case 1:
        cout << "you entered 1"  << endl;
        // do things here:  if 1 is passed to the function
        break;
    case 2:
        cout << "you entered 2" << endl;
        // do things here:  if 2 is passed to the function
        break;
    default:
        cout << "Error: 1 and 2 are valid inputs only!" << endl;
        break;
    }
}
you entered 1
you entered 2
1 and 2 are valid inputs only!


Feel free to ask any questions about what I wrote or if something does not make sense. :)
Last edited on
Topic archived. No new replies allowed.