Is it possible to input pi?

I have written a piece of code to solve a differential equation using Euler's method. The code allows the user to input where they would like the solution to approximate at, but I'd like the user to be able to input either a numerical value or something like pi/2 as the function is trigonometric. Is it possible to use cin in this way? Thanks a lot.
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

#include <cmath>
#include <iostream>
#include <fstream>

int main()
{
        //declare constants and variables
        double t=0.0;
        double dt=0.0;
        double pi=acos(-1);
        double b=0.0;
        double a=0.0;
        double y=0.0;
        int i=0;

        FILE * pFile;
        pFile = fopen("Eulers.txt", "w");

        printf("%s","Enter t value to calculate function at: ");
        fprintf(pFile, "value of t to evaluate function: ");
        std::cin >> b;
        printf("%s", "Enter interval to be used: ");
        fprintf(pFile, "interval used: ");
        std::cin >> dt;
        double step=(b-a)/dt;

        for (int i=0; i<=step; i++)
        {
                t=i*dt; //increases time each iteration
                y=y+(1+pow(y,2))*dt;
                printf("\n %i %f", i, y);
                fprintf(pFile, "%i %f", i, y);
        }

	fclose (pFile);
        return 0;
}
No, there is no built-in way to allow expression like that. You'll have to write the parser yourself or look for an existing library that does the job.
Topic archived. No new replies allowed.