how can i make a programm that has as input only capital letters

i need help!!
Can you be a little more specific?
Get the ascii
And see if it is less than or equal to the ascii of A.

or just let the user enter any case. If it is small. Add 26 to its ascii.
Could just use the toupper() function on any input?
Questions like this make me sad.
Activate the Caps Lock key and then break it off.
Caps lock won't work if the user presses shift. biplav's method is best.
You have to take 32 from it, not add 26.

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

using namespace std;

int main(void)
{
    string input = "";

    cout << "Hello. How are we today?\n\n>> ";

    cin >> input;

    for(int i = 0; i < input.length(); i++)
    {
        if(input[i] >= 'a' && input[i] <= 'z')
        {
            input[i] -= 32;
        }
    }

    cout << "\nYou said:\n\n<< " << input << endl;

    // Pause the program.

    return 0;
}
There is a funciton in #include <cctype> called isupper(ch), ch is a char variable, that returns true if ch is an uppercase character, false otherwise.
Last edited on
Answers like these to questsions like these make me sad.

OP Title wrote:
how can i make a programm that has as input only capital letters

You can't - not without using a library like ncurses to modify the input as it is typed. And trust me, this is not worth the effort to do, so just don't do it. Learn to live with people who don't type in all caps for your programs.
Last edited on
1
2
$ perl -pe 's/[^A-Z]//g' | ./program.bin
$ echo 'only capital letters' | ./program.bin
Platform independent?
So, what is wrong with just using toupper()/tolower()?
He wants the visible input on screen to automagically turn into all-caps, as far as I know given the title of the OP.
Is that even possible in a console?
Yes, but it's not worth the effort :p
Caps lock won't work if the user presses shift. biplav's method is best.

That was a joke of course. I was also assuming that the OP wanted to modify the input stream, not just convert (toupper). It's a moot point I guess since the OP has not returned...
Topic archived. No new replies allowed.