FlyingSixtySix FlyingSixtySix - 2 months ago 10
C++ Question

What is '...': undeclared identifier and how do I fix it?

StackOverflow. I've been writing a simplistic application in C++ for fun, but I've run into some issues that leave me baffled.

Alright, so, the problem arose when I started declaring everything in different functions, outside of main. Here is all of my code, hopes up that this is resolved.

Sorry, forgot to include, but all of the voids are shown as '(name)': undeclared identifier. Everything else has "function call missing argument list."

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

void hang()
{
int hang;
cin >> hang;
}

void cls()
{
system("cls");
}

void exitapp()
{
exit(0);
}

void menu()
{
cls;
cout << "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n";
cout << "=+= MAIN MENU =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n";
cout << "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n";
cout << "=+= 1] Take the survey +=+=+=+=+=+=+=+=+=+=+=+=+=+=\n";
cout << "=+= 2] 20 plus 20 =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n";
cout << "=+= 3] Exit the application =+=+=+=+=+=+=+=+=+=+=+=\n";
cout << "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n";
string menuselection;
cin >> menuselection;
if (menuselection == "1")
{
menuitem1;
}
if (menuselection == "2")
{
menuitem2;
}
if (menuselection == "3")
{
menuitem3;
}
}

void backtomainmenu()
{
string backtomm;
cin >> backtomm;
if (backtomm == "")
{
cls;
menu;
}
}

void menuitem1()
{
survey;
}

void menuitem2()
{
int number1;
int number2;
int sum = number1 + number2;
string backtomainmenu;
cout << "Enter the first number: ";
cin >> number1;
cout << "Enter the second number: ";
cin >> number2;
cout << "The sum of the two numbers is: " << sum << "\n";
cout << "Press enter to continue.";
cin >> backtomainmenu;
if (backtomainmenu == "")
{

}
}

void menuitem3()
{
exitapp;
}

void survey()
{
string name;
int age;
int number;
cout << "What is your name?\n";
cin >> name;
cout << "What is your age?\n";
cin >> age;
cout << "What is a random number?\n";
cin >> number;
cout << "Hello, " << name << "! I know you are " << age << " years old, and the random number you selected was " << number << ".\n";
Sleep(2000);
cls;
}

int main()
{
menu();
}

Answer

You must call functions using parentheses always! So, use menu() when this function does not have any parameters.