Advertisement
Ravenxa

Miniräknare :D

Feb 8th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. double addition(double num1, double num2)
  8. {
  9.     return num1 + num2;
  10. }
  11.  
  12. double subtraction(double num1, double num2)
  13. {
  14.     return num1 - num2;
  15. }
  16.  
  17. double multiplication(double num1, double num2)
  18. {
  19.     return num1 *  num2;
  20. }
  21.  
  22. double division(double num1, double num2)
  23. {
  24.     return num1 / num2;
  25. }
  26. int main()
  27. {
  28.     cout << "Welcome to the Ultimate Calculator of Lord Nur.\n";
  29.     double number1;
  30.     double number2;
  31.     int choice;
  32.     cout << "What do you want to do?\n 1 = Adding.\n 2 = Subtracting.\n 3 = Multiplying.\n 4 = Dividing.\n" << endl;
  33.     cout << "Choice: ";
  34.     cin >> choice;
  35.     if (choice==1)
  36.     {
  37.         // Addition
  38.         cout << "You are adding, enter the first number you would like to add. \nNumber 1:";
  39.         cin >> number1;
  40.         cout << "Enter the second number. \nNumber 2: ";
  41.         cin >> number2;
  42.         cout << "The result is: " << addition(number1, number2) << endl;
  43.     }
  44.     else
  45.     {
  46.         if (choice == 2)
  47.         {
  48.             // Subtraction
  49.             cout << "You are subtracting, enter the first number you would like to subtract. \nNumber 1:";
  50.             cin >> number1;
  51.             cout << "Enter the second number. \nNumber 2: ";
  52.             cin >> number2;
  53.             cout << "The result is: " << subtraction(number1, number2) << endl;
  54.         }
  55.     else
  56.         {
  57.             if (choice==3)
  58.             {
  59.             // Multiplication
  60.             cout << "You are multiplying, enter the first number you would like to multiply. \nNumber 1:";
  61.             cin >> number1;
  62.             cout << "Enter the second number. \nNumber 2: ";
  63.             cin >> number2;
  64.             cout << "The result is: " << multiplication(number1, number2) << endl;
  65.         }
  66.             else
  67.             {
  68.                 {
  69.                     // Division
  70.                     cout << "You are dividing, enter the first number you would like to divide. \nNumber 1:";
  71.                     cin >> number1;
  72.                     cout << "Enter the second number. \nNumber 2:";
  73.                     cin >> number2;
  74.                     cout << "The result is: " << division(number1, number2) << endl;
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     int choice2;
  80.     cout << "Do you want to keep calculating or quit?\n1 = Keep calculating.\n2 = Quit.\n" << endl;
  81.     cout << "Choice: ";
  82.     cin >> choice2;
  83.     if (choice2 == 1)
  84.     {
  85.         cout << "What do you want to do?\n 1 = Adding.\n 2 = Subtracting.\n 3 = Multiplying.\n 4 = Dividing.\n";
  86.             cin >> choice;
  87.     }
  88.     else
  89.     {
  90.         return 0;
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement