"Missing default parameter" using functions

The object of this assignment is to ask the user whether they'd like first class or economy seating for a flight, and get their input. The program should assign the user to a seat and display it to them. Neither seating section can hold more than 5 seats, so when one section is full, the program should ask the user if they'd like a seat in the other section. If yes, assign and display. If not, give them the message "Next flight leaves in 3 hours."

I chose to use functions.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;

void firstClass (int i=0, int j=0, char alt);
void economyClass (int j=0, int i=0, char alt);

int main ()
{
	int selection, i=0, j=0;
	char alt;

	cout << "Please select your preferred class. Enter 1 for first class, or 2 for economy class: " ;
	cin >> selection;

	if (selection == 1)
	{
		firstClass (i=0, j=0, alt);
	}

	else if (selection == 2)
	{
		economyClass (j=0, i=0, alt);
	}

	return 0;
}

void firstClass (int i=0, int j=0, char alt)
{
	if (i <= 5)
	{
		cout << "Your seat assignment is seat number " << i << " in the first class section." << endl;
		i++;
	}

	else if (i > 5)
	{
		cout << "First class seating is full. Would you like a seat in economy class? Enter Y for yes or N for no: " << endl;
		cin >> alt;
		{
			if (alt == 'Y')
			{
				economyClass (j=0, i=0, alt);
			}
			else if (alt == 'N')
				cout << "The next flight leaves in 3 hours." << endl;
		}
	}
}

void economyClass (int j=0, int i=0, char alt)
{
	if (j <= 5)
	{
		cout << "Your seat assignment is seat number " << j << " in the first class section." << endl;
		j++;
	}

	else if (j > 5)
	{
		cout << "Economy class seating is full. Would you like a seat in first class? Enter Y for yes or N for no: " << endl;
		cin >> alt;
		{
			if (alt == 'Y')
			{
				firstClass (i=0, j=0, alt);
			}
			else if (alt == 'N')
				cout << "The next flight leaves in 3 hours." << endl;
		}
	}
}


The snytax error I'm getting (the red line is under the function names in the prototype and the function names at the beginning of the actual functions) is that I am missing a default parameter. I can't figure out what that means. And I'm not sure my parameters are entirely correct beyond that anyways.

Also, I don't know if you can call a function from a function other than main?

Chances are, I have a couple of other errors, but I'd like to start here if that is okay.


Thank you in advance :)

- MMC
Last edited on
You can't have only the first two parameters and not the last take default parameters. If you specify any parameter to have a default value, all the following ones must as well. You may reorder them if you like.
I think you have a slight misunderstanding of how default arguments work and how to use them:

http://cplusplus.com/doc/tutorial/functions2/

Try re-reading that section and see if you can find out the problem.

Also, I don't know if you can call a function from a function other than main?


You can.
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
#include <iostream>
#include <string> 
// my function interaction 
char first();
char second(char c);
char third(int i);
char forth(char c);
char fifth(int i); 
std::string last(int i); 

int main(){
    std::cout << last(1); 
    return 0; 
} 


char first(){
return 'h'; 
}
char second(char c){
    if(c == 'g') return 'e';
    else return NULL; 
}
char third(int i){
    switch (i) {
        case 1:
            return 'l';
            break;
            
        default:
            return NULL; 
            break;
    }
}
char forth(char c){
    return c; 
}
       
char fifth(int i){
    if(i != 10) return 'a';
    else return 'o';
}
std::string last(int i){
    std::string returnS; 
    returnS = first(); 
    returnS += second('g');
    returnS += third(i); 
    returnS += forth('l'); 
    returnS += fifth(10); 
    return returnS; 
}

i threw this together to show how functions work. think this out and you will get functions a lot better. hope it helps.
Topic archived. No new replies allowed.