Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <windows.h>
- #include <ctype.h>
- using namespace std;
- int main()
- {
- int callchoice = -1; // Call choice, used to simplify the switch cases
- char option = 0; // Selecting an option from a menu
- int coinin = -1; // User entering coins
- int cointotal = 0; // Total of coins
- char phonein[20]; // Int isn't long enough for mobile number
- int countdown = 0; // Countdown for time left
- const char CALLTYPES[3][14] = { "Local",
- "Trunk",
- "International",
- };
- const int CALLPRICES[3] = { 20, // Local call
- 10, // Trunk call
- 4, // International call
- };
- system("pause");
- do
- {
- system("cls");
- cout << "\n\n\n\t========== Telephone kiosk Menu ==========" << endl; // Display menu
- cout << "\tL - Local" << endl;
- cout << "\tT - Trunk" << endl;
- cout << "\tI - International" << endl;
- cout << "\tE - Exit" << endl;
- cout << "\t======================================" << endl;
- cout << "\tPlease enter L, T, I or E to Exit: ";
- cin >> option; option = toupper(option); // Get option, in UPPERCASE
- system("cls"); // Clear menu, regardless of choice
- if (option == 'L') callchoice = 0; // Used for characteristics of call types
- else if (option == 'T') callchoice = 1; // Used for characteristics of call types
- else if (option == 'I') callchoice = 2; // Used for characteristics of call types
- else if (option == 'E') break; // Exit
- if ((callchoice >= 0) && (callchoice <= 2)) // If it's a valid call choice
- {
- do // Taking the coins -- MAKE IT VALIDATE, IF STATEMENT
- {
- cout << "Total entered: " << cointotal << "p\n\n";
- cout << "You have requested a ";
- cout << CALLTYPES[callchoice] << " call.";
- cout << "\nThe charge for this type of call is 10p for ";
- cout << CALLPRICES[callchoice] << " seconds.";
- cout << "\n\nPlease insert your coins now...\n\n";
- cout << "Coin In (Enter 0 to finish): ";
- cin >> coinin;
- if (cin.fail()) // Stops it looping infinitely for letters
- {
- cin.clear();
- cin.ignore(numeric_limits<short>::max(),'\n');
- }
- if ((coinin == 5) || (coinin == 10) || (coinin == 20) || // Get coin value
- (coinin == 50) || (coinin == 100))
- {
- cointotal+=coinin; // Add to total if correct
- }
- system("cls");
- } while (coinin != 0);
- system("cls");
- if (cointotal < 10) // Less than 10 entered
- {
- cout << "Sorry, you have not entered enough coins. ";
- cout << "Please change call type or enter more.";
- } else { // More than 10 entered
- cout << "Please enter the number you wish to call.\n";
- cout << "Number: ";
- cin >> phonein; // Validate?
- system("cls");
- cout << "Now dialling";
- Sleep(2500);
- system("cls");
- for (countdown = (cointotal / 10) * CALLPRICES[callchoice]; // Countdown, time left
- countdown > 0; countdown--)
- {
- system("cls");
- cout << "Connected to " << phonein;
- cout << " - Please start your conversation";
- cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
- cout << "\t\t\t\t\t\t\t";
- cout << "Time Left: " << countdown << " seconds";
- Sleep(1000);
- }
- system("cls");
- cout << "Sorry, your time is now up. Call disconnected. ";
- break; // Exit, call finished!
- }
- }
- option = 0; // Reset option to loop back to menu, invalid entry
- } while (option != 'E'); // If option == E, exit application
- cout << "Exiting.";
- Sleep(5000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement