I was already trying to write a console based simple program to find if the entered character is uppercase, lowercase, or a number (which could be a floating point value).
Please have a look on the code which also contains my questions and comments. Thanks. I understand it take a lot time and energy to help with such stuff. I genuinely appreciate your help. Please don't forget I'm an outright beginner.
// istream peek
#include <iostream>
usingnamespace std;
int main ()
{
char c; // what is c here?int n; // n is an integer value, right?char str[256]; // could you please tell what this is?
cout << "Enter a number or a word: ";
c=cin.peek(); // what is this? i have seen terms with () are at the top?if ( (c >= '0') && (c <= '9') ) // can't c be less than 0 and greater than 9?
{
cin >> n;
cout << "You have entered number " << n << endl;
}
else
{
cin >> str;
cout << " You have entered word " << str << endl;
}
return 0; // what function does it serve here?
}
int main ()
{
char c; // what is c here? this is a Temporary holder of info of a single character type.
int n; // n is an integer value, right? This is a holder of number type.
char str[256]; // could you please tell what this is? this is a block of data of single character type 256 elements long.
cout << "Enter a number or a word: ";
c=cin.peek(); // what is this? i have seen terms with () are at the top?
// Peek is basically looking at the first character that was entered in.
if ( (c >= '0') && (c <= '9') ) // can't c be less than 0 and greater than 9? Correct.
// tests similar to this one would test for 'a' to 'z' for a lowercase or 'A' to 'Z' for uppercase.
{
// If it falls in this we need to populate n for a actual integer.
cin >> n;
cout << "You have entered number " << n << endl;
}
else
{
//If we fall here we are filling str[256]
cin >> str;
cout << " You have entered word " << str << endl;
}
return 0; // what function does it serve here?
// if you look at the top it has 'int' in front of 'main' This is returning an integer type that 'main' is requiring. If it isn't present you might get a warning in a compiler.
}