Identifiers

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.
So....where the code you've written so far?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#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";
}
Well the first question is do you know the rules for a valid C++ identifier? If not, then you need to look them up.

Do you know how to iterate over a string char by char?
Topic archived. No new replies allowed.