Help with functions

Iam trying to turn my code into a functin but i keep getting errors that say im redefinig parameters. I think im messing up when by defining within the parameter but im not sure.

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

int num_check(int num);
int num_check2(int num2);
void letter_counter(char x, char c, char d, int &a, int&b, int&e);



int main() {


	
	int  w = 0, x = 0, y = 0, z = 0, k = 0;
	int pretty_category, so_category, ugly_category;
	int category;
	string type1, type2, type3, type4, type5;

	char p = 'P';
	char s = 'S';
	char u = 'U';
	cout << "How many flowers are in the Pretty Category?" << endl;
	pretty_category = num_check(x);
	cout << "How many flowers are in the So-So Category?" << endl;
	so_category = num_check(y);
	cout << "How many flowers are in the Ugly Category?" << endl;
	ugly_category = num_check(z);

	cout << "How many categories are in this basket" << endl;
	category = num_check2(w);

	if (category == 1) {
		cout << "What category for the 1st bunch: " << endl;
		letter_counter(p,s,u, pretty_category,so_category,ugly_category);

	}

	else if (category == 2) {
		cout << "What category for the 1st bunch: " << endl;
		cin >> type1;
		cout << "What category for the 2nd bunch: " << endl;
		cin >> type2;
	}
	else if (category == 3) {
		cout << "What category for the 1st bunch: " << endl;
		cin >> type1;
		cout << "What category for the 2nd bunch: " << endl;
		cin >> type2;
		cout << "What category for the 1st bunch: " << endl;
		cin >> type3;

	}
	else if (category == 4) {
		cout << "What category for the 1st bunch: " << endl;
		cin >> type1;
		cout << "What category for the 2nd bunch: " << endl;
		cin >> type2;
		cout << "What category for the 1st bunch: " << endl;
		cin >> type3;
		cout << "What category for the 1st bunch: " << endl;
		cin >> type4;
	}
	else if (category == 5) {
		cout << "What category for the 1st bunch: " << endl;
		cin >> type1;
		cout << "What category for the 2nd bunch: " << endl;
		cin >> type2;
		cout << "What category for the 1st bunch: " << endl;
		cin >> type3;
		cout << "What category for the 1st bunch: " << endl;
		cin >> type4;
		cout << "What category for the 1st bunch: " << endl;
		cin >> type5;
	}








	system("pause");
	return 0;
}



int num_check(int num) {

	cin >> num;
	while (num < 0) {
		cout << "Error try again" << endl;
		cin >> num;
	}
	return num;
}

int num_check2(int num2) {
	cin >> num2;

	while (num2 < 1 || num2>5) {
		cout << "Error try again" << endl;
		cin >> num2;
	}


	return num2;
}
void letter_counter(char x,char c, char d,int &a,int&b,int&e) {
	char input;
	int counter = 0;

	cin >> input;
	
if (toupper(input) == x && a>=1) {
	cout << "Sounds good" << endl;
	--a;
	++counter;

	}
else if(toupper(input) ==c && b >= 1) {
	cout << "Sounds good" << endl;
	--b;
	++counter;
	}
else if(toupper(input) == d && e>= 1) {
	cout << "Sounds good" << endl;
	--c;
	++counter;
}
else {
	cout<< "Invalid Input" << endl;
}
cout << a << endl;
}
Last edited on
remove the default parameters in function prototype
Thanks that worked, but can you give a quick explanation on why that is?
@fivestar

When you forward declare a function your telling the compiler that it exists. Your also giving the compiler enough information about the function to know that it exists. But in a forward declaration you do not need to give the compiler information about default parameters.
Topic archived. No new replies allowed.