calling a string

**THIS IS A CODE GIVEN TO ME BY ANOTHER USER**
i got stuck on lines 6, 7, 8 because i cant call the string.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #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 6:
			get1(a, "computing a log b");
			cout << "result is " << log10(a) << endl;
			break;
		case 7:
			get2(a, b, "computing a^b");
			cout << "result is " << pow(a, b) << endl;
			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;
		case 1:
			get2(a, b, "Computing a * b");
			cout << "result is " << a * b << '\n';
			break;
		case 3: 
			get2(a, b, "Computing a-b");
			cout << "result is " << a - b << '\n';
			break;
		case 4:
			get2(a, b, "Computing a+b");
			cout << "result is " << a + b << '\n';
		}
	}
}
gitelmana wrote:
**THIS IS A CODE GIVEN TO ME BY ANOTHER USER**

Cheating!!!

gitelmana wrote:
i got stuck on lines 6, 7, 8 because i cant call the string.

Pardon? What do you mean by that?



1
2
			get1(a, "computing a log b");
			cout << "result is " << log10(a) << endl;

That's not mathematically correct. (You have coded "a log 10", not "a log b".)
Last edited on
Yeah "a log b" was an error I fixed, I dont know why I wrote that...
And line 8 it says " no operator "<<" matches these operands"
Last edited on
#include <string>
also, he gave me that code to help me with a different problem that, he helped me solve the mess of a "program" i created...
Topic archived. No new replies allowed.