Hello i need some help with my menu i don't know ho to make it call some of the functions.I am still a beginner.
Thanks!
Code:
#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 info");
cout << ("2 - Showing all of the contacts with a debt beyond 100");
cout << ("3 - Quit");
int menu = 0;
cin>> menu;
switch (menu) {
case 1: { input(contact s[]); }
case 2: { spravka(contact s[]);}
case 3: return 0;
}
return 0;
}