how can i modify my code so it can handle upper and lower case characters.. for this:

cout << "(B)uy, (S)ell, (H)old or (Q)uit: ";
cin >> ans;

what should i add to the code? i added #include <cctype>.

Recommended Answers

All 4 Replies

after the cin line call either toupper() or tolower() then make the test.

after the cin line call either toupper() or tolower() then make the test.

No, to test use isupper() or islower() .

No, to test use isupper() or islower() .

Depends on what you're testing. In this case, to test whether a character is 'b' or 'B', use toupper or tolower:

char someChar = 'b';
if (toupper (someChar) == 'B')
{
    cout << "It is either a 'b' or a 'B'.";
}

Do you need the original input? If not, you can just tolower()(or upper) the entire input, as it will do nothing if it is already lower(or uppercase).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.