Hi everyone,

I've written a test program, and I need help limiting the amount of characters a user enters in a char. I want it so that that maximum amount of characters is 1, and if they enter more than 1, it will display a message. Here's my code:

#include <iostream>
using namespace std;

int main()
  cout << "The current value is 0. Enter a '+' to increment," << endl;
  cout << "and a '-' to decrement. Enter a 'T' to terminate the loop." << endl << endl;

 int value = 0;
 cout << "Enter next operator: ";
 cin >> operation;

if the character's bigger than 1,
display 'invalid' message

    case '+' :
      goto loop;
    case '-' :
      goto loop;

    case 'T' :
    case 't' :
      cout << "The loop was terminated. The accumulated value is " << value << "." << endl << endl;
      return 0;

      cout << "You have entered an invalid operator. You must " << endl
      << "either enter a '+' to increment, a '-' to decrement," << endl
      << "or a 'T' to terminate the loop." << endl << endl;

      goto loop;

As commented in the code above, 'if the character's greater than 1, display 'invalid' message'.
could anyone help me put this in the correct syntax?

Thanks in advance.

delete all those goto statements and replace them with standard C/C++ loop statements. You should consider goto as a forbidden word.

Here is a thread -- Just to short-circuit discussion of something that has already been beaten to death.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.