Namespace

So I'm getting some errors I can't account for in this code I'm writing. It's only very simple code, and I haven't been learning C++ for very long so I know some of my variable names may not be particularly descriptive and stuff like that, but that's not what I need help with, so please, just help with the errors.

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
#include <iostream>

int trig()
{
	float x;
	float y;
	char op;
	
	cout << "Choose a trigonometry operation ('s' for sin, 'c' for cos or 't' for tan): " << endl;
	cin >> op >> endl;
	
	if (op == 's')
		cin << "Enter the opposite side: " << endl;
	cin >> x >> endl;
	cout << "Enter the hypotenuse: " << endl;
	cin >> y >> endl;
	cout << "sin of " << x << "/" << y << " = " << x/y << endl;
	
	if (op == 'c')
		cin << "Enter the adjacent side: " << endl;
	cin >> x >> endl;
	cout << "Enter the hypotenuse: " << endl;
	cin >> y >> endl;
	cout << "cos of " << x << "/" << y << " = " << x/y <<endl;
	
	if (op == 't')
		cout << "Enter the opposite side: " << endl;
	cin >> x >> endl;
	cout << "Enter the adjacent side: " << endl;
	cin >> y >> "\n"
	cout << "cos of " << x << "/" << y << " = " << x/y << endl;
}	

int standard()
{
	float x;
	char op;
	float y;
	
	cin << "You have selected standard mode" << endl;
	cin << "Please enter a number up to 2 decimal points: " << endl;
	cin >> x >> endl;
	cin << "Please enter an operator (choose from +,-,* or /): " << endl;
	cin >> op >> endl;
	cin << "Please enter a second number up to 2 decimal places: " << endl;
	cin >> y >> endl;
	
	if (op == '+')
		cin << x << " + " << y << " = " << x+y << endl;
	
	if (op == '-')
		cin << x << " - " << y << " = " << x-y << endl;
	
	if (op == '*')
		cin << x << " * " << y << " = " << x*y << endl;
	
	if (op == '/')
		cin << x << " / " << y << " = " << x/y << endl;
}	

int main()
{	
	char mode;
	cin << "Choose a mode - standard or trigonometry operations ('s' for standard or 't' for trigonometry): " << endl;
	cin >> mode >> endl;
	
	if (mode == 's')
		standard()
	
	if (mode == 't')
		trig()
}




/Users/Keelan/Desktop/Advanced Calculator/main.cpp:9:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:9: error: 'cout' was not declared in this scope


/Users/Keelan/Desktop/Advanced Calculator/main.cpp:9:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:9: error: 'endl' was not declared in this scope


/Users/Keelan/Desktop/Advanced Calculator/main.cpp:10:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:10: error: 'cin' was not declared in this scope


/Users/Keelan/Desktop/Advanced Calculator/main.cpp:40:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:40: error: 'cin' was not declared in this scope


/Users/Keelan/Desktop/Advanced Calculator/main.cpp:40:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:40: error: 'endl' was not declared in this scope


/Users/Keelan/Desktop/Advanced Calculator/main.cpp:65:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:65: error: no match for 'operator<<' in 'std::cin << "Choose a mode - standard or trigonometry operations (\'s\' for standard or \'t\' for trigonometry): "'


/Users/Keelan/Desktop/Advanced Calculator/main.cpp:66:0 /Users/Keelan/Desktop/Advanced Calculator/main.cpp:66: error: no match for 'operator>>' in 'std::operator>> [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>](((std::basic_istream<char, std::char_traits<char> >&)(& std::cin)), ((char&)(& mode))) >> std::endl'

at the very top you got to say using namespace std;

after the includes
Last edited on
I HAD that line in, but removed it as it was giving me even more errors. Not sure if I put it right at the top though, will try. Thanks

EDIT: tried that, gives me more errors again:



Category: Error: Other

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:12:0 No match for 'operator>>' in 'std::operator>> [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>](((std::basic_istream<char, std::char_traits<char> >&)(& std::cin)), ((char&)(& op))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:15:0 No match for 'operator<<' in 'std::cin << "Enter the opposite side: "'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:16:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& x))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:18:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& y))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:22:0 No match for 'operator<<' in 'std::cin << "Enter the adjacent side: "'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:23:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& x))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:25:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& y))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:30:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& x))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:32:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& y))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:42:0 No match for 'operator<<' in 'std::cin << "You have selected standard mode"'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:43:0 No match for 'operator<<' in 'std::cin << "Please enter a number up to 2 decimal points: "'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:44:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& x))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:45:0 No match for 'operator<<' in 'std::cin << "Please enter an operator (choose from +,-,* or /): "'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:46:0 No match for 'operator>>' in 'std::operator>> [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>](((std::basic_istream<char, std::char_traits<char> >&)(& std::cin)), ((char&)(& op))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:47:0 No match for 'operator<<' in 'std::cin << "Please enter a second number up to 2 decimal places: "'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:48:0 No match for 'operator>>' in 'std::cin. std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((float&)(& y))) >> std::endl'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:51:0 No match for 'operator<<' in 'std::cin << x'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:54:0 No match for 'operator<<' in 'std::cin << x'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:57:0 No match for 'operator<<' in 'std::cin << x'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:60:0 No match for 'operator<<' in 'std::cin << x'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:67:0 No match for 'operator<<' in 'std::cin << "Choose a mode - standard or trigonometry operations (\'s\' for standard or \'t\' for trigonometry): "'

/Users/Keelan/Desktop/Advanced Calculator/main.cpp:68:0 No match for 'operator>>' in 'std::operator>> [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>](((std::basic_istream<char, std::char_traits<char> >&)(& std::cin)), ((char&)(& mode))) >> std::endl'
Last edited on
1
2
3
#include <iostream>

using namespace std;


remove '>>endl' at cin

makesure operator (>>) in cin, not (<<) , 'cin<<'
I see some cin functions done wrong:

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
int standard()
{
	float x;
	char op;
	float y;
	
	cin << "You have selected standard mode" << endl;
	cin << "Please enter a number up to 2 decimal points: " << endl;
	cin >> x >> endl;
	cin << "Please enter an operator (choose from +,-,* or /): " << endl;
	cin >> op >> endl;
	cin << "Please enter a second number up to 2 decimal places: " << endl;
	cin >> y >> endl;
	
	if (op == '+')
		cin << x << " + " << y << " = " << x+y << endl;
	
	if (op == '-')
		cin << x << " - " << y << " = " << x-y << endl;
	
	if (op == '*')
		cin << x << " * " << y << " = " << x*y << endl;
	
	if (op == '/')
		cin << x << " / " << y << " = " << x/y << endl;
}	


I think you meant to do cout <<
Last edited on
@keelan1234

I think where you have ..
1
2
3
4
5
6
7
8
if (op == '+')
		cin << x << " + " << y << " = " << x+y << endl;
	if (op == '-')
		cin << x << " - " << y << " = " << x-y << endl;
	if (op == '*')
		cin << x << " * " << y << " = " << x*y << endl;
	if (op == '/')
		cin << x << " / " << y << " = " << x/y << endl;


You meant to put..

1
2
3
4
5
6
7
8
if (op == '+')
		cout << x << " + " << y << " = " << x+y << endl;
	if (op == '-')
		cout << x << " - " << y << " = " << x-y << endl;
	if (op == '*')
		cout << x << " * " << y << " = " << x*y << endl;
	if (op == '/')
		cout << x << " / " << y << " = " << x/y << endl;
Even where he says cin << "You have selected standard mode" << endl;

It should be replaced with cout <<
Topic archived. No new replies allowed.