I'm a CS student. I'm new to this field. The most challenging part for me is how to start the program. I'm not looking for the full/final answer, I just need some guidance.
here is the questions,
Write a program (test_char.cpp) that asks the user to input a character. Then,:
- Check to see if the character entered is one of the following choices:
1. an uppercase letter
2. A lower case letter.
3. A digit
4. A whitespace (including single space, newline, vertical tab, regular tab)
5. None of the above
- you can't use of the cctype library functions (isapha, isdigit, etc)
- Allow the user to repeat the process as many times as he/she wants.
Are we allowed to assume ASCII or some kind of character encoding where a-z, A-Z, and 0-9 are contiguous? (I don't know how many people still use e.g. EBCDIC, but...)
If so, you can check if the character is >= 'a' and <= 'z' for lowercase, >= 'A' and <= 'Z' for uppercase, and similarly for digits.
Ok so this is what I have so far,
#include <iostream>
using namespace std;
int main()
{
int lower_case, upper_case, count;
char c;
if (c >= 'a' && c <= 'z')
cout << lower_case;
if (c >= 'A' && c <= 'Z')
cout << upper_case;
if (c >= 97 && c <= 122)
cout << lower_case;
if (c >= 65 && c >= 90);
cout << upper_case;
count++;
cout << "c\ " << c << "\" has " << count <<"whitespace\n";
return 0;
}
when I try to run the program it says variables: c, lower_case and upper_case hasn't been initialized yet. I don't know what to do
cout << "enter the input\n";
cin.get(input);
{
if (input >= 97 && input <= 122)
cout << " this is a lowercase input\n";
}
{
if (input >= 65 && input <= 90)
cout << " this is an uppercase input\n";
}
{
if (input >= '0' && input <= '9')
cout << " this is a digit input\n";
}
{
if (input == '\n' && input == ' ' && input =='\v' && input == '\t')
cout << " this is a whitespace input\n";
}
if (input == '%')
cout << "none of the above\n";
return 0;
}