Need help with an equation

How do I get an output like this using cin.peek?

1
2
3
4
Please enter an expression (like `4 * 5` or `ln 5`): 4 * 5
4 * 5 = 20
Please enter an expression (like `4 * 5` or `ln 5`): ln 5
ln 5 = 1.60944


I did it wrong bu I don't really understand how to do this stuff.


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
#include <cmath>
// pow()

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <string>
using std::string;


int main() {
    double  a;         // to hold the user's first real number
    double  b;         // to hold the user's second real number
    string expression;  // to hold the user's operation

    cout << "Please enter an expression: ";
    cin >> a;

    cout << "Please enter an exprssion (* || ln): ";
    cin >> expression;

    cout << "Please enter an expression: ";
    cin >> b;

    cout << endl;

    cout << a << " " << operation << " " << b << " = ";

    if ( (4*5 == a) || ( ln 5 == b) )
        cout << a + b;
    		cout << " The" << a << "has to equal 20";
		else
			cout << "--- The integer you entered is not divisible by 2 and 3,"
			" or by 5 and 7, or\n"
			<< "both.\n";
	}


    cout << endl;

    return 0;  // success
}
Last edited on
Topic archived. No new replies allowed.