I have to write a program that determines whether the user’s input qualifies as a valid C++ identifier. You prompt the user to input an identifier and press enter immediately after. The program should use a WHILE LOOP to read a string that represents an identifier CHAR BY CHAR. Your program applies the actual rules for a valid C++ identifier and then let the user know the result. It should output the diagnosis as well.
IMPORTANT NOTE: YOU SHOULD NOT USE PRE-DEFINED STRING FUNCTIONS,
ARRAYS.
Example output:
Please enter a C++ identifier and press enter immediately after:
_numOfWord$
This is NOT a valid C++ identifier.
Error in position 10: Invalid symbol $.
Another example:
Please enter a C++ identifier and press enter immediately after:
2ndDigit
This is NOT a valid C++ identifier.
Error in position 0: Starts with a digit.
#include <iostream>
#include <cctype>
#include <limits>
int main()
{
std::cout << "Do you want someone to do all the work for you? ";
char answer { };
std::cin >> answer;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (::toupper(answer) == 'Y' ) { std::cout << "Post it in the Jobs section.\n"; }
else { std::cout << "Show what you have coded so far.\n"; }
std::cout << "Good luck.\n";
}