1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <math.h>
using namespace std;
void get1(double &a, const string &prompt)
{
cout << prompt << '\n';
cout << "please enter a: ";
cin >> a;
}
void get2(double &a, double &b, const string &prompt)
{
get1(a, prompt); // Call get1() to get the first value.
cout << "please enter b: ";
cin >> b;
}
int
main()
{
double a,b;
int c;
while (true) {
cout <<
"please chose an operation: for mult. put 1, for dev but 2 for sub put 3, for addition put 4, square root is 5, log is 6, exponents is 7, enter 8 for derivative"
<< endl;
cout << "Press ctrl-d to exit\n";
cin >> c;
if (!cin) break; // exit the loop on error or end of file
switch(c) {
case 8:
case 6:
case 7:
cout << "Not yet implemented";
break;
case 2:
get2(a,b, "Computing a/b");
cout << "result is " << a/b << '\n';
break;
case 5:
get1(a, "Computing sqrt(a)");
cout << "result is " << sqrt(a) << '\n';
break;
}
}
}
| |