#include <iostream>
#include <fstream>
#include <string>
usingnamespace 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;
}
}
}
}
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.
#include <iostream>
#include <fstream>
#include <string>
usingnamespace 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;
}
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.