Advertisement
adambkehl

Assignment #3 (1/3) - Page 377 #10

Feb 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double add(double x, double y);
  5. double calculate(double a, double b, double(*add)(double, double));
  6.  
  7. int main() {
  8.     double firstNum, secondNum;
  9.  
  10.     for (int i = 1; i <= 3; i++) {
  11.         cout << "(" << i << "/3 loop iterations)" << endl;
  12.         cout << "Enter your first number: "; cin >> firstNum;
  13.         cout << "Enter your second number: "; cin >> secondNum;
  14.         cout << "Combined is: " << calculate(firstNum, secondNum, add) << endl << endl;
  15.     }
  16.     cout << "Press enter to exit.";
  17.     cin.get(), cin.get();
  18.     return 0;
  19. }
  20.  
  21. double add(double x, double y) {
  22.     return x + y;
  23. }
  24.  
  25. double calculate(double a, double b, double (*add)(double, double)){
  26.     return (*add)(a, b);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement