I need to debug my program.

Hello i need some help debugging my c++ program. Thx.

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

struct contact
{
	string firstname;
	string secondname;
	int number;
	int debt;
};
void initialize(contact s[])
{
	cout << "Initialising the array and the file" << endl;
	for (int i = 0; i < 3; i++)
	{
		s[i].firstname = " ";
		s[i].secondname = " ";
		s[i].number = 0;
		s[i].debt = 0;
	}
}
void input(contact s[])
{
	cout << "Input of the data into the array and the file" << endl;
	ofstream myfile;
	myfile.open("sample.txt");
	for (int i = 0; i < 3; i++)
	{
		cout << "Enter the contact`s first name :" << endl;
		cin >> s[i].firstname;
		myfile << s[i].firstname << endl;
		cout << "Enter the contact`s second name :" << endl;
		cin >> s[i].secondname;
		myfile << s[i].secondname << endl;
		cout << "Enter the contact`s number :" << endl;
		cin >> s[i].number;
		myfile << s[i].number << endl;
		cout << "Enter the contact`s debt :" << endl;
		cin >> s[i].debt;
		myfile << s[i].debt << endl;
	}
}
void output(contact s[])
{
	cout << "Outputing all of the data " << endl;
	for (int i = 0; i < 3; i++)
	{
		cout << "The contact`s first name is: " << s[i].firstname << endl;
		cout << "The contact`s second name is: " << s[i].secondname << endl;
		cout << "The contact`s number is: " << s[i].number << endl;
		cout << "The contact`s debt is: " << s[i].debt << endl;
	}
}
void spravka(contact s[])
{
	cout << "Showing all of the contacts with a debt beyond 100" << endl;
	for (int i = 0; i < 3; i++)
	{
		if (s[i].debt > 100)
		{
			cout << "The contact`s first name is: " << s[i].firstname << endl;
			cout << "The contact`s second name is: " << s[i].secondname << endl;
			cout << "The contact`s number is: " << s[i].number << endl;
			cout << "The contact`s debt is: " << s[i].debt << endl;
		}

	}
	void BubbleSort(contact b[])
	{
		int i, j, flag = 1;
		int temp;
		for (i = 1; i < 3 && flag; i++)
		{
			flag = 0;
			for (j = 0; j < (3 - 1); j++)
			{
				if (b[j + 1].debt > b[j].debt)
				{
					temp = b[j];
					b[j] = b[j + 1];
					b[j + 1] = temp;
					flag = 1;
				}
			}
		}
	}
You've forgotten to have a main() function, and the function void spravka(contact s[]) never finishes.
Last edited on
Thx, i fixed them but i have got another problem when trying to add a menu with the option to chose some of the functions.I had some errors with the void BubbleSort(contact b[]) function but i removed it for now.

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


struct contact
{
	string firstname;
	string secondname;
	int number;
	int debt;
};
void initialize(contact s[])
{
	cout << "Initialising the array and the file" << endl;
	for (int i = 0; i < 3; i++)
	{
		s[i].firstname = " ";
		s[i].secondname = " ";
		s[i].number = 0;
		s[i].debt = 0;
	}
}
void input(contact s[])
{
	cout << "Input of the data into the array and the file" << endl;
	ofstream myfile;
	myfile.open("sample.txt");
	for (int i = 0; i < 3; i++)
	{
		cout << "Enter the contact`s first name :" << endl;
		cin >> s[i].firstname;
		myfile << s[i].firstname << endl;
		cout << "Enter the contact`s second name :" << endl;
		cin >> s[i].secondname;
		myfile << s[i].secondname << endl;
		cout << "Enter the contact`s number :" << endl;
		cin >> s[i].number;
		myfile << s[i].number << endl;
		cout << "Enter the contact`s debt :" << endl;
		cin >> s[i].debt;
		myfile << s[i].debt << endl;
	}
}
void output(contact s[])
{
	cout << "Outputing all of the data " << endl;
	for (int i = 0; i < 3; i++)
	{
		cout << "The contact`s first name is: " << s[i].firstname << endl;
		cout << "The contact`s second name is: " << s[i].secondname << endl;
		cout << "The contact`s number is: " << s[i].number << endl;
		cout << "The contact`s debt is: " << s[i].debt << endl;
	}
}
void spravka(contact s[])
{
	cout << "Showing all of the contacts with a debt beyond 100" << endl;
	for (int i = 0; i < 3; i++)
	{
		if (s[i].debt > 100)
		{
			cout << "The contact`s first name is: " << s[i].firstname << endl;
			cout << "The contact`s second name is: " << s[i].secondname << endl;
			cout << "The contact`s number is: " << s[i].number << endl;
			cout << "The contact`s debt is: " << s[i].debt << endl;
		}

	}
}

	int main() {




		cout << ("1 - Enter the contact");

		cout << ("2 - Showing all of the contacts with a debt beyond 100");

		cout << ("3 - Quitn");


		char i;


		cin>>("%c", &i);

		if (i < '1' || i > '3') goto SCAN;

		SCAN:

		switch (i) {

		case '1': input(contact s[]);  

		case '2':  spravka(contact s[]); 

		case '3': return 0;

		}



		return 0;

	}
Last edited on
1
2
3
if (i < '1' || i > '3') goto SCAN;

		SCAN:


This makes no sense.
I think its ok now but i don't know how to go back to the function when i choose from the menu.I get this error "E016 too few arguments in function call", what argument i need to add ? Thx for the help.

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
int main() {




		cout << ("1 - Enter the contact");

		cout << ("2 - Showing all of the contacts with a debt beyond 100");

		cout << ("3 - Quitn");

		int menu = 0;
		cin>> menu;


	

		switch (menu) {

		case '1': { input(); }

		case '2': { spravka();}

		case '3': return 0;

		}



		return 0;

	}
Your functions take parameters.
void input(contact s[]) input expects an array of contact objects.

What are you providing?
case '1': { input(); } Nothing.

i don't know how to go back

http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.