Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <windows.h>
  3. #include <ctype.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int callchoice = -1; // Call choice, used to simplify the switch cases
  10. char option = 0; // Selecting an option from a menu
  11. int coinin = -1; // User entering coins
  12. int cointotal = 0; // Total of coins
  13. char phonein[20]; // Int isn't long enough for mobile number
  14. int countdown = 0; // Countdown for time left
  15. const char CALLTYPES[3][14] = { "Local",
  16. "Trunk",
  17. "International",
  18. };
  19. const int CALLPRICES[3] = { 20, // Local call
  20. 10, // Trunk call
  21. 4, // International call
  22. };
  23.  
  24. system("pause");
  25.  
  26. do
  27. {
  28. system("cls");
  29. cout << "\n\n\n\t========== Telephone kiosk Menu ==========" << endl; // Display menu
  30. cout << "\tL - Local" << endl;
  31. cout << "\tT - Trunk" << endl;
  32. cout << "\tI - International" << endl;
  33. cout << "\tE - Exit" << endl;
  34. cout << "\t======================================" << endl;
  35. cout << "\tPlease enter L, T, I or E to Exit: ";
  36. cin >> option; option = toupper(option); // Get option, in UPPERCASE
  37.  
  38. system("cls"); // Clear menu, regardless of choice
  39.  
  40. if (option == 'L') callchoice = 0; // Used for characteristics of call types
  41. else if (option == 'T') callchoice = 1; // Used for characteristics of call types
  42. else if (option == 'I') callchoice = 2; // Used for characteristics of call types
  43. else if (option == 'E') break; // Exit
  44.  
  45. if ((callchoice >= 0) && (callchoice <= 2)) // If it's a valid call choice
  46. {
  47. do // Taking the coins -- MAKE IT VALIDATE, IF STATEMENT
  48. {
  49. cout << "Total entered: " << cointotal << "p\n\n";
  50.  
  51. cout << "You have requested a ";
  52. cout << CALLTYPES[callchoice] << " call.";
  53. cout << "\nThe charge for this type of call is 10p for ";
  54. cout << CALLPRICES[callchoice] << " seconds.";
  55.  
  56. cout << "\n\nPlease insert your coins now...\n\n";
  57. cout << "Coin In (Enter 0 to finish): ";
  58. cin >> coinin;
  59. if (cin.fail()) // Stops it looping infinitely for letters
  60. {
  61. cin.clear();
  62. cin.ignore(numeric_limits<short>::max(),'\n');
  63. }
  64. if ((coinin == 5) || (coinin == 10) || (coinin == 20) || // Get coin value
  65. (coinin == 50) || (coinin == 100))
  66. {
  67. cointotal+=coinin; // Add to total if correct
  68. }
  69. system("cls");
  70. } while (coinin != 0);
  71.  
  72. system("cls");
  73.  
  74. if (cointotal < 10) // Less than 10 entered
  75. {
  76. cout << "Sorry, you have not entered enough coins. ";
  77. cout << "Please change call type or enter more.";
  78. } else { // More than 10 entered
  79. cout << "Please enter the number you wish to call.\n";
  80. cout << "Number: ";
  81. cin >> phonein; // Validate?
  82. system("cls");
  83. cout << "Now dialling";
  84. Sleep(2500);
  85. system("cls");
  86. for (countdown = (cointotal / 10) * CALLPRICES[callchoice]; // Countdown, time left
  87. countdown > 0; countdown--)
  88. {
  89. system("cls");
  90. cout << "Connected to " << phonein;
  91. cout << " - Please start your conversation";
  92. cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
  93. cout << "\t\t\t\t\t\t\t";
  94. cout << "Time Left: " << countdown << " seconds";
  95. Sleep(1000);
  96. }
  97. system("cls");
  98. cout << "Sorry, your time is now up. Call disconnected. ";
  99. break; // Exit, call finished!
  100. }
  101. }
  102. option = 0; // Reset option to loop back to menu, invalid entry
  103. } while (option != 'E'); // If option == E, exit application
  104.  
  105. cout << "Exiting.";
  106. Sleep(5000);
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement