Thread: Incoming phone call program for C++

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    9

    Incoming phone call program for C++

    Newbie here!!!!

    I just started taking C++ in college and I know this is C++ basic, but trying to wrap my head around it.

    We are to create a program (basically scheduling appointment by phone) asking to input 1, 2 or 3 (which is an office location), then it will ask for an appointment type (1, 2, 3, or 4). Once this is completed, it will show the proper message(12 different options) e.g.

    Office location:
    Press 1 for Syracuse office
    Press 2 for Albany office
    Press 3 for Rochester office
    (once the above is selected)

    Press 1 new appointment
    Press 2 reschedule appointment
    Press 3 Billing
    Press 4 Talk to nurse

    after these have been selected, (you now can see the 12 different messages that can be shown) and should show the following:

    e.g. you pressed 2 for office and then pressed 3 for billing, Message should show
    Rochester: billing question

    This has to be done using the Swith form and or the else/if, or else if!
    Any input would greatly be appreciated,

    Bill

    I have the following:
    Code:
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main()
    {
        //Declare variables
        int officeNumber = 0;
        int selectionNumber = 0;
    
        //Input data
        cout << "Enter office number." << endl;
        cout << "Press 1 for Syracuse office " << endl;
        cout << "Press 2 for Albany office " << endl;
        cout << "Press 3 for Rochester office " << endl;
        cin >> officeNumber;
        cout << "Enter selection number." << endl;
        cout << "Press 1 for making new appointment" << endl;
        cout << "Press 2 for rescheduling an appointment" << endl;
        cout << "Press 3 for billing questions" << endl;
        cout << "Press 4 for talking to a nurse" << endl;
        cin >> selectionNumber;
        
        //Begin SWITCH & Display selection
        switch (selectionNumber)
        {
          case 1: cout << "?????: " << endl;
                  break;
          case 2: cout << "?????: " << endl;
                  break;
          case 3: cout << "?????: " << endl;
                   break;                                        
          default: cout << "INPUT ERROR" << endl;
        }//End SWITCH
    system("pause");
    return 0; 
    }

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    120
    Here is one way of doing it. Obviously, I didn't finish it, but I did get it started and the rest should be self explanatory. There is probably a more efficient way of doing it but I'm too tired to think right now.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
    
        //Declare variables
        int officeNumber = 0;
        int selectionNumber = 0;
    
        //Input data
        cout << "Enter office number." << endl;
        cout << "Press 1 for Syracuse office " << endl;
        cout << "Press 2 for Albany office " << endl;
        cout << "Press 3 for Rochester office " << endl;
        cin >> officeNumber;
    
    
        cout << "Enter selection number." << endl;
        cout << "Press 1 for making new appointment" << endl;
        cout << "Press 2 for rescheduling an appointment" << endl;
        cout << "Press 3 for billing questions" << endl;
        cout << "Press 4 for talking to a nurse" << endl;
        cin >> selectionNumber;
        
        if (officeNumber == 1 && selectionNumber == 1)
    	{
    		cout << " Saracuse : Making new appt.\n";
    	}
    
    	else if (officeNumber == 1 && selectionNumber == 2)
    	{
    		cout << " Saracuse: Rescheduling appt\n";
    
    	}
    system("pause");
    return 0; 
    }

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Try not to do people's homework for them. That's no good for anyone.

    OP:
    You can print 2 parts of the message in 2 switch statements.

    Code:
    switch (officeNumber) {
    ...
    }
    switch (selectionNumber) {
    ...
    }

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    9
    I woke up this morning thinking Else if as well, lengthy but would work....

    Thanks for the tip Nick!

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    9
    Thanks CF,

    I am glad you didn't do my homework, one can't learn if someone does it for you!

    I'll take your input and play with that as well...

    Many thanks for the suggestions all!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Can c legacy program call c++ library?
    By happylee in forum C Programming
    Replies: 2
    Last Post: 02-20-2002, 12:57 PM
  4. Call COBOL program
    By PeterH in forum C Programming
    Replies: 1
    Last Post: 12-05-2001, 01:54 AM
  5. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 06:57 AM