Program not taking lower case inputs

why is my code not taking lower case inputs? I have the toupper function included.

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

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main()
{

	char function;
	double val;

	cout << "This calculator requires you to enter a funtion and a number" << endl;
	cout << "The functions are as follows: " << endl;
	cout << "S - sine " << endl;
	cout << "C - cosine " << endl;
	cout << "T - tangent " << endl;
	cout << "R - square root " << endl;
	cout << "N - natural log " << endl;
	cout << "X - exit the program " << endl;

	cout << endl;

	cout << "Please enter a function and a value: " << endl;
	cin >> function >> val;

	while (toupper(function) != 'X')
	{
	
		switch (function)
		{
		case 'S':
			cout << "The sine of your number is " << sin(val) << endl;
			break;
		case 'C':
			cout << "The cosine of your number is " << cos(val) << endl;
			break;
		case 'T':
			cout << "The tangent of your number is " << tan(val) << endl;
			break;
		case 'R':
			cout << "The square root of your number is " << sqrt(val) << endl;
			break;
		case 'N':
			cout << "The natural log of your number is " << log(val) << endl;
			break;
		case 'X':
			break;
		}

		cout << "Please enter a function and a value: " << endl;
		cin >> function >> val;

	}

	cout << "Thanks for using the calculator" << endl;

	return 0;
}
Last edited on
Maybe include <cctype>

and exclude it from the while (toupper(function) != 'X')

to do something like

1
2
3
function = toupper(function);

while(function != 'X')
Last edited on
Topic archived. No new replies allowed.