Stuck in calling function in case statement.

Hey guys,

I'm a little stuck here trying to work on this program. For the life of me I can't figure out why when i call a function in a case statement it gives me the error.

In function 'int main()':
37 17 [Error] expected primary-expression before 'int'
37 29 [Error] expected primary-expression before 'int'
37 44 [Error] expected primary-expression before 'int'
37 60 [Error] expected primary-expression before 'int'

some background on the program.

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

#include <iostream>
#include <string> 
#include <iomanip>
#include <fstream>

using namespace std;

void numberCount(int number, int &oddCount, int &evenCount, int &zeroCount);
int largest();

int main ()
{
	int num;
	char choice;
	do {
		cout << "Welcome to my progam!" << endl << endl;
		cout << "Here are your following options:" <<endl;
		cout << "(a) Find the largest list of positive numbers (-1) to quit" << endl;
		cout << "(b) Given a positive number display the number of even, odd, and zero digits in the number" << endl;
		cout << "(c) quit the program."<< endl;
		cout << "Please enter your choice: ";
		cin >> choice;
		
		switch (choice){
			case 'a':
				largest();
				break;
			case 'b':
				numberCount(int number, int &oddCount, int &evenCount, int &zeroCount);
				break;
			case 'c':
			cout  << "Thank you for using my program!" << endl;
			return 0;
			break;	
		}
	}while(choice!='c');
}

int largest(int num){
	
	do { /* The function does not take any parameters. So, you can read all your input in the
function. It returns an int, which is the largest number to main. Use a loop to
read the numbers until the user enters -1 to quit. As you read, keep track of the
largest number. When the user enters -1, stop reading and return the largest
number to the main function. Do NOT use an array for this program. */
		cout << "Please enter a number. Enter (-1) to quit: ";
		cin >> num;
		
	}while(num!= -1);
	
}

void numberCount(int number, int &oddCount, int &evenCount, int &zeroCount){
	/* Write a function that takes as a parameter an integer, and returns the number of
odd, even and zero digits. This should be a void function since a function cannot
return 3 values*/
}
Last edited on
When you call a function you should not list the parameter types before the argument names.
Is there something that I am missing here cause I am still getting the same error?

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
#include <iostream>
#include <string> 
#include <iomanip>
#include <fstream>

using namespace std;



int largest(int num){
	
	do { /* The function does not take any parameters. So, you can read all your input in the
function. It returns an int, which is the largest number to main. Use a loop to
read the numbers until the user enters -1 to quit. As you read, keep track of the
largest number. When the user enters -1, stop reading and return the largest
number to the main function. Do NOT use an array for this program. */
		cout << "Please enter a number. Enter (-1) to quit: ";
		cin >> num;
		
	}while(num!= -1);
	
}

void numberCount(int number, int &oddCount, int &evenCount, int &zeroCount){
	/* Write a function that takes as a parameter an integer, and returns the number of
odd, even and zero digits. This should be a void function since a function cannot
return 3 values*/
}

int main ()
{
	int num, number, oddCount, evenCount, zeroCount;
	char choice;
	do {
		cout << "Welcome to my progam!" << endl << endl;
		cout << "Here are your following options:" <<endl;
		cout << "(a) Find the largest list of positive numbers (-1) to quit" << endl;
		cout << "(b) Given a positive number display the number of even, odd, and zero digits in the number" << endl;
		cout << "(c) quit the program."<< endl;
		cout << "Please enter your choice: ";
		cin >> choice;
		
		switch (choice){
			case 'a':
				largest(num);
				break;
			case 'b':
				numberCount(int number, int& oddCount, int& evenCount, int& zeroCount);
				break;
			case 'c':
			cout  << "Thank you for using my program!" << endl;
			return 0;
			break;	
		}
	}while(choice!='c');
}
Not sure what has changed. The problem is when you call the numberCount function. You should not have all the int and int& there.
I just erased all of the int and int& and now I am getting

In function 'int main()':
53 13 [Error] too few arguments to function 'int largest(int)'
18 5 [Note] declared here
56 17 [Error] too few arguments to function 'void numberCount(int, int&, int&, int&)'
32 6 [Note] declared here
You still need to pass the argument values, you should just not mention the types in the function call.
Last edited on
The issue is that I have to use those types :/

Write a function that takes as a parameter an integer, and returns the number of
odd, even and zero digits. This should be a void function since a function cannot
return 3 values. Here is your function signature:
void numberCount(int number, int &oddCount, int &evenCount, int
&zeroCount);
Ok, I will be more thorough. When you define/declare the function you need to have the types as you have it. The problem is on line 30 in your first post (line 48 in your second post).

 
numberCount(int number, int& oddCount, int& evenCount, int& zeroCount);

Change it to:

 
numberCount(number, oddCount, evenCount, zeroCount);

Thanks for explaining it that way i got it. I was up late last night and just trying to get it done and i was stuck there. Thank you for the help peter.
Topic archived. No new replies allowed.