Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- int main()
- {
- restart_calculator:
- system("mode 58, 23");
- char endChoice;
- do{
- system("cls");
- cout << "================\n C++ CALCULATOR\n================" << endl;
- //Input first number
- cout << "\n\n Choose the first number (use \".\" for decimals): " << endl;
- double firstNumber;
- cin >> firstNumber;
- //Input second number
- cout << "\n Now choose the second number (use \".\" for decimals): " << endl;
- double secondNumber;
- cin >> secondNumber;
- //Input operation
- cout << "\n Choose your operation ( +, -, * or / )" << endl;
- char operation;
- cin >> operation;
- //Case switch for operations
- switch(operation){
- case '+':
- {
- cout << "\n The result is: " << firstNumber + secondNumber << endl;
- break;
- }
- case '-':
- {
- cout << "\n The result is: " << firstNumber - secondNumber << endl;
- break;
- }
- case '*':
- {
- cout << "\n The result is: " << firstNumber * secondNumber << endl;
- break;
- }
- case '/':
- {
- cout << "\n The result is: " << firstNumber / secondNumber << endl;
- break;
- }
- default:
- {
- cout << "\n Please, next time, choose a valid operation!" << endl;
- }
- }
- cout << "\n\n--------------------------\nDeveloped by Wolfiy\n" << "\nMake another calcul? [Y/N]" << endl;
- //End Switch
- restart_ask:
- cin >> endChoice;
- switch(endChoice){
- case 'N': case 'n':
- {
- exit(0);
- }
- case 'Y': case 'y':
- {
- continue;
- }
- default:
- {
- do{
- cout << "\n Please, select between Y (yes) and N (no)." << endl;
- cin >> endChoice;
- if(endChoice == 'N' || 'n'){
- exit(0);
- }
- else if(endChoice == 'Y' || 'y'){
- goto restart_calculator;
- }
- else{
- goto restart_ask;
- }
- }while(endChoice != 'Y' || 'y' || 'N' || 'n');
- }
- }
- }while(endChoice == 'Y', 'y');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement