Calculator

just an error i cant get through...

error C3861: 'atanf2': identifier not found

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main()
{
	int num = 0;
	cout << "1) cos(x), 2) sin(x), 3) tan(x), 4) atan2(y, x), 5) sqrt(x), 6) x^y," << endl;
        cout << "7) ln(x), 8) e^x, 9) |x|, 10) floor(x), 11) ceil(x), 12) Exit." << endl;
	cin >> num;

	bool quit = true;
	float x = 0.0f;
	float y = 0.0f;
	string operation_name = "";
        float z = y / x;   
	float operation = 0.0f;


while( quit )
{
	cout << "Enter x: ";
	cin >> x;

	if ( x == 3 || x == 4 || x == 6 )
	{
	      cout << "Enter y: ";
	      cin >> y;
	}
	else if ( x == 12 )
	{
		cout << "Exiting..." << endl;
                quit = false;
        }

	switch( num )
	{
	case 1:
		operation = cosf(x);
		operation_name = "cos(x)";
		break;
	case 2:
		operation = sinf(x);
		operation_name = "sin(x)";
		break;
	case 3:
		operation = tanf(x);
		operation_name = "tan(x)";
		break;
	case 4:
		operation = atanf2(z);    
		operation_name = "atan2(y, x)";
		break;
	case 5:
		operation = sqrtf(x);
		operation_name = "sqrt(x)";
		break;
	case 6:
		operation = powf(x, y);
		operation_name = "x^y";
		break;
	case 7:
		operation = logf(x);
		operation_name = "ln(x)";
		break;
	case 8:
		operation = expf(x);
		operation_name = "e^x";
		break;
	case 9:
		operation = fabsf(x);
		operation_name = "|x|";
		break;
	case 10:
		operation = floorf(x);
		operation_name = "floor(x)";
		break;
	case 11:
		operation = ceilf(x);
		operation_name = "ceil(x)";
		break;
	default:
		quit = false;
		break;
	}
	
	cout << operation_name << operation << endl;

}
}



solution? ty
Last edited on
Define a prototype of atanf2() above main().
Well, it's because you aren't defining it anywhere....define it above main or prototype it and define in another header file or something.
i know float atanf2(float y, float x); is the prototype, but dont know how to define it correctly
you could"ve said use functions but ok

ive used it like so:

1
2
3
4
5
6
float atanf2(float y, float x)
{
	float r;
	r = atanf2(y, x);
	return r;
}


but program exits...
Last edited on
well first thing i see is, it looks like atanf uses 2 arguements, you only pass it one.
that shouldn't necessarily cause it to exit unless its crashing because its taking in an arbitrary value or address, which it also has absolutely no reason to do.
also i assume you've prototyped it something like
float atanf2(float y, float x);
or you inserted the entire function before the main()
Last edited on
With that implementation of atanf2 you are creating an infinite loop
omegazero yea ive fixed that already, so it has 2 parameters but its the same problem (ive edited the code above so its like so):

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

	float x = 0.0f;
	float y = 0.0f;
	string operation_name = "";
        float z = y / x;   
	float operation = 0.0f;

float atanf2(float y, float x)
{
 	float r;
	r = atanf2(y, x);
	return r;
}

int main()
{
	bool quit = true;     
	while( quit )         
	{
	int num = 0;
	cout << "1) cos(x), 2) sin(x), 3) tan(x), 4) atan2(y, x), 5) sqrt(x), 6) x^y," << endl;
    cout << "7) ln(x), 8) e^x, 9) |x|, 10) floor(x), 11) ceil(x), 12) Exit." << endl;
	cin >> num;

	if( num == 12)
	{        
		cout << "Exiting..." << endl;
		break; 
	}

	cout << "Enter x: ";
	cin >> x;

	if ( num == 3 || num == 4 || num == 6 )
	{
	      cout << "Enter y: ";
	      cin >> y;
	}

	switch( num )
	{
	case 1:
		operation = cosf(x);
		operation_name = "cos(x)";
		break;
	case 2:
		operation = sinf(x);
		operation_name = "sin(x)";
		break;
	case 3:
		operation = tanf(x);
		operation_name = "tan(x)";
		break;
	case 4:
		operation = r;      
		operation_name = "atan2(y, x)";
		break;
	case 5:
		operation = sqrtf(x);
		operation_name = "sqrt(x)";
		break;
	case 6:
		operation = powf(x, y);
		operation_name = "x^y";
		break;
	case 7:
		operation = logf(x);
		operation_name = "ln(x)";
		break;
	case 8:
		operation = expf(x);
		operation_name = "e^x";
		break;
	case 9:
		operation = fabsf(x);
		operation_name = "|x|";
		break;
	case 10:
		operation = floorf(x);
		operation_name = "floor(x)";
		break;
	case 11:
		operation = ceilf(x);
		operation_name = "ceil(x)";
		break;
	/*default:
		quit = false;
		break;*/            
	}
	
	cout << operation_name << " = " << operation << endl;

  
}
}


but why do you have to even do that, i mean why it isnt in the cmath, in the way tan,cos,... are
-> is the declaration right, OR i have to to do it so:

1
2
3
4
5
6
7
8
9
10
void atanf2(float y, float x)
{
	
	if( x > 0 )
	{
		theta = atanf(y/x)*180/3.14;
	}
	else
		theta = atanf(y/x)*180/3.14 + 180;
}


but as ive heard, you dont have to type all that code, just somehow implement it, am i right?

well ive tried "a couple" of ways to solve this, but the only way i can get it run correctly, is if i use this atanf2 function ive written here (well not in this example but ok :D)


Last edited on
Topic archived. No new replies allowed.