fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int globalVar = 10;
  5.  
  6. int arithmeticOperations(int a, int b) {
  7. int resultSubtract = a - b;
  8. int resultMultiply = a * b;
  9. cout << "Subtraction result: " << resultSubtract << endl;
  10. cout << "Multiplication result: " << resultMultiply << endl;
  11.  
  12. return resultSubtract;
  13. return resultMultiply;
  14. }
  15.  
  16. int main() {
  17. int arr[] = { 1, 34, 56, 7, 12 };
  18.  
  19. int x, y;
  20.  
  21. cout << "Enter the first number: ";
  22. cin >> x;
  23. cout << "Enter the second number: ";
  24. cin >> y;
  25.  
  26. arithmeticOperations(x, y);
  27.  
  28. string input;
  29. cout << "Enter 'yes' or 'no': ";
  30. cin >> input;
  31.  
  32. if (input == "yes") {
  33. cout << "You entered 'yes'!" << endl;
  34. }
  35. else if (input == "no") {
  36. cout << "You entered 'no'!" << endl;
  37. }
  38. else {
  39. cout << "Unknown input!" << endl;
  40. }
  41.  
  42. int option;
  43. cout << "Enter a number between 1 and 3: ";
  44. cin >> option;
  45.  
  46. switch (option) {
  47. case 1:
  48. cout << "You chose the first option" << endl;
  49. break;
  50. case 2:
  51. cout << "You chose the second option" << endl;
  52. break;
  53. case 3:
  54. cout << "You chose the third option" << endl;
  55. break;
  56. default:
  57. cout << "Invalid choice" << endl;
  58. }
  59.  
  60. for (int i = 0; i < 5; i++) {
  61. cout << "Array element (after) [" << i << "] = " << arithmeticOperations(arr[i], globalVar) << endl;
  62. }
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Enter the first number: Enter the second number: Subtraction result: 1721487096
Multiplication result: 0
Enter 'yes' or 'no': Unknown input!
Enter a number between 1 and 3: Invalid choice
Array element (after) [0] = Subtraction result: -9
Multiplication result: 10
-9
Array element (after) [1] = Subtraction result: 24
Multiplication result: 340
24
Array element (after) [2] = Subtraction result: 46
Multiplication result: 560
46
Array element (after) [3] = Subtraction result: -3
Multiplication result: 70
-3
Array element (after) [4] = Subtraction result: 2
Multiplication result: 120
2