-3

When I was searching for new information through source code in the internet, I saw someone used goto to a variable, and this variable was linked with a cout statement, the same as in std::cout.

He wrote a:cout.

Can you help me to find the name of this function?

void Main_Menu() {
    int i;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t  HOSPITAL MANAGEMENT SYSTEM \n\n";
    cout << "\n\n\t\t\t\t\t\tPlease,  Choose from the following Options: \n\n";
    cout << "\t\t\t\t\t\t _________________________________________________________________ \n";
    cout << "\t\t\t\t\t\t|                                                                |\n";
    cout << "\t\t\t\t\t\t|             1  >> Add New Patient Record                        |\n";
    cout << "\t\t\t\t\t\t|             2  >> Add Diagnosis Information                     |\n";
    cout << "\t\t\t\t\t\t|             3  >> Full History of the Patient                   |\n";
    cout << "\t\t\t\t\t\t|             4  >> Information About the Hospital                |\n";
    cout << "\t\t\t\t\t\t|             5  >> Exit the Program                              |\n";
    cout << "\t\t\t\t\t\t|_________________________________________________________________|\n\n";
a:  cout << "\t\t\t\t\t\tEnter your choice: "; 
cin >> i;
if (i > 5 || i < 1) { 
    cout << "\n\n\t\t\t\t\t\tInvalid Choice\n"; 
    cout << "\t\t\t\t\t\tTry again...........\n\n"; 
    goto a; 
} //if inputed choice is other than given choice
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 3
    Are you asking about `goto` and labels, because that's what this code is doing. – Stephen Newell Feb 20 '21 at 15:38
  • 1
    BTW, Use spaces instead of tabs. A tab can represent 8, 3, 4, or 2 spaces. A tab can mean to space over to the next tab stop (which may be intermittent). Tabs can also be ignored. – Thomas Matthews Feb 20 '21 at 19:09

1 Answers1

2

There is no variable a linked to cout. The a: is a label that you can jump to with goto a;. The code could also be written like

a:
  cout << "\t\t\t\t\t\tEnter your choice: ";
  cin >> i;
  if (i > 5 || i < 1) {
    cout << "\n\n\t\t\t\t\t\tInvalid Choice\n";
    cout << "\t\t\t\t\t\tTry again...........\n\n";
    goto a;
  } //if inputed choice is other than given choice

Funny side note: why is

void f()
{
  http://stackoverflow.com
  https://stackoverflow.com
}

valid C? Because http and https are seen as labels and // starts a comment.

Werner Henze
  • 16,404
  • 12
  • 44
  • 69