Thread: Problem making a "Menu" calling functions .

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    2

    Problem making a "Menu" calling functions .

    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;
    
        }
    Last edited by Tox1c; 12-07-2018 at 07:55 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Also here -> I need to debug my program. - C++ Forum

    It's odd that you managed to write all the functions, yet can't make even a basic attempt to call them.

    Code:
    contact myContacts[3];
    /// 
    input(myContacts);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    2
    Thanks!I used some examples while writing the program i made an attempt to call them but i removed it after i had an error.And i posted the question on 2 forums in hope to get the answer faster.


  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > And i posted the question on 2 forums in hope to get the answer faster.
    How To Ask Questions The Smart Way

    Or people who would otherwise help you will soon cotton on that you're a cross-poster and just assume answering your question is a waste of effort because someone else is sure to have answered it elsewhere.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2014, 08:12 PM
  2. Marking functions as "Local" or "Global"
    By zyxwvuts in forum C Programming
    Replies: 10
    Last Post: 02-22-2014, 07:58 AM
  3. Calling C functions from a "parallel" (MPI) Fortran program
    By Nooby 1 Kenooby in forum C Programming
    Replies: 2
    Last Post: 04-25-2013, 04:45 AM
  4. Replies: 2
    Last Post: 11-03-2012, 08:50 AM
  5. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM

Tags for this Thread