tolower not working

I am having a user input his selection from a menu. In order to prevent confusion when the user inputs a lower or uppercase char I am converting the input by using the tolower function.

It works correctly on the first two menu selections, but when the user inputs the uppercase char to quit the program, the program does not terminate. It jumps to the appropriate switch case, displays the appropriate message, but then continues to re-display the menu.

My guestimation is that it has something to do with the do-while loop interfering, but I am not sure how to fix it. Any ideas?
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
#include"giftwrap.h"

int main()
{
	cout << setprecision(2) << fixed;
	string name = "Sally's Gifts";
	char selection;
	double length, width, height, price, tax = 0;
	GiftWrap sallys(.0925, .0025);
	GiftWrap sallys2;
	do
	{
	cout << "GIFT WRAP INVOICE GENERATOR" << endl;
	cout << "--------------------------------" << endl;
	cout << "a) Generate Gift Wrap Invoice" << endl;
	cout << "b) Generate Gift Wrap Invoice for bargain size" << endl;
	cout << "q) Quit" << endl;
	cin >> selection;
	cin.clear();
	cin.ignore();
	cout << endl;
	
		switch (tolower(selection))
		{
			case 'a':
				cout << "Please enter the length of the box you wish to wrap: ";
				cin >> length;
				sallys.setLength(length);
				cout << "Please enter the width of the box: ";
				cin >> width;
				sallys.setWidth(width);
				cout << "Please enter the height of the box: ";
				cin >> height;
				sallys.setHeight(height);
				cout << "GIFT WRAP INVOICE" << " - " << name << endl;
				cout << "------------------------------------" << endl;
				cout << "Box Length: " << sallys.getLength() << endl;
				cout << "Box Width: " << sallys.getWidth() << endl;
				cout << "Box Height: " << sallys.getHeight() << endl;
				cout << "Price Per Inch: " << setprecision(4) << sallys.getPrice() << endl;
				cout << endl;
				cout << "SUBTOTAL: " << setw(8) << " " << setprecision(2) << sallys.calcSubTotal() << endl;
				cout << "TAX: " << setw(13) << " " << sallys.calcTax() << endl;
				cout << setw(12) << " " << "----------" << endl;
				cout << "TOTAL: " << setw(10) << " " << sallys.calcTotal() << endl;
				cout << endl;
				break;
			case 'b':
				cout << "GIFT WRAP INVOICE" << " - " << name << endl;
				cout << "------------------------------------" << endl;
				cout << "Box Length: " << sallys2.getLength() << endl;
				cout << "Box Width: " << sallys2.getWidth() << endl;
				cout << "Box Height: " << sallys2.getHeight() << endl;
				cout << "Price Per Inch: " << setprecision(3) << sallys2.getPrice() << endl;
				cout << endl;
				cout << "SUBTOTAL: " << setw(8) << " " << setprecision(2) << sallys2.calcSubTotal() << endl;
				cout << "TAX: " << setw(13) << " " <<  sallys2.calcTax() << endl;
				cout << setw(12) << " " << "----------" << endl;
				cout << "TOTAL: " << setw(10) << " " << sallys2.calcTotal() << endl;
				cout << endl;
				break;
			case 'q':
				cout << "Program terminated." << endl;
				cout << endl;
				break;
			default:
				cout << "Invalid Selection" << endl;
				cout << endl;
				break;
		}
	} while (selection != 'q');
	
	system("pause");
	return 0;
}
Hi,
} while (selection != 'q');

Should be :
} while (tolower(selection) != 'q');
Does that help you? :)
Topic archived. No new replies allowed.