I posted about this last night however a new problem has happened. I want the code to be able to understand when i enter a lower case letter that it goes in the "if statement" for lower case and same for upper case and numbers between 0-9 however when the code is run, you get the proper ASCII value for the character that was input but it always puts it in the 'numbers group' statement. How can I fix this? also sorry if re-posting is not allowed.
#include <iostream>
#include <iomanip>
#include <time.h>
usingnamespace std;
int main()
{
cout<< "Enter either a upper case letter, a lower case letter, or a number between 0-9: ";
char nInput = '0';
nInput != 'A', 'a';
char Ucap = 'A';
Ucap != '0', 'a';
char Lcap = 'a';
Lcap != '0', 'A';
char answer;
cin>> nInput && Ucap && Lcap; /* I know this is wrong but unsure how to fix*/
if(nInput){
cout<<"You entered " << nInput << " which has a ASCII value of " << (int)nInput << ". " <<endl;
cout<< nInput << " is part of the Numbers Group."<<endl;
}elseif(Ucap){
cout<<"You entered " << Ucap << " which has a ASCII value of " << (int)Ucap << ". " <<endl;
cout<< Ucap << " is part of the Upper Case Group."<<endl;
}elseif(Lcap){
cout<<"You entered " << Lcap << " which has a ASCII value of " << (int)Lcap << ". " <<endl;
cout<< Lcap << " is part of the Lower Case Group."<<endl;
}
system("pause");
return 0;
}
#include <iostream>
#include <cctype>
int main()
{
char nInput;
std::cout<< "Enter either a upper case letter, a lower case letter, or a number between 0-9: ";
std::cin >> nInput;
std::cout << "You entered \"" << nInput << "\" ";
if (isupper(nInput)) {
std::cout << "which is upper case\n";
} elseif (islower(nInput)) {
std::cout << "which is lower case\n";
} elseif (isdigit(nInput)) {
std::cout << "which is a digit\n";
} else {
std::cout << "which isn't a letter or digit\n";
}
}
it is just cout.
your program has "using namespace std". If you don't do that, you have to invoke the namespace to use cout, and that uses the :: operator.
so putting it all together, you say std::cout << "text"; //this is the same as cout << "text"; in your program.
The standard namespace has gotten so large (namespace std) that it has so many things in it that people sometimes accidentally re-create an entity that is in it, and this causes strange bugs. It is considered better to qualify each item with std:: instead of using the huge namespace and risking those kinds of errors.