user15457633
user15457633

Reputation: 1

Something was not decleared in this scope

for my code, I wanted to call a function that I had finished into the switch case function. But whenever I try to run, it shows me that I had not declared in the scope.

Below is my code:

void mainpage(Admin a)
{

        time_t t = time(NULL);
        tm* timePtr = localtime(&t);
        cout<< "Date : "<<timePtr->tm_mday<<"-"<<timePtr->tm_mon+1<<"-"<<timePtr->tm_year + 1900<<"\nTime : "<< timePtr->tm_hour <<":"<<timePtr->tm_min;
        int choice=0;

            cout<<"\n-----------------------------";
            cout<<"\nMovie Ticket Booking System";
            cout<<"\n-----------------------------";
            cout<<"\nUSER INFO";
            cout<<"\n <1> ADMIN";
            cout<<"\n <2> CUSTOMER";
            cout<<"\n <3> CURRENTLY SHOWING";
            cout<<"\n <4> Exit \n\n";
            cout<<"Enter Your Choice : ";

            cin>>choice;

            switch(choice)
            {
            case 1:
                a.admin();
                break;
            case 2:
                c.customer();
                break;
            case 3:
                s.shows();
                break;
            case 4:
                cout<< "\nThank you for choosing us. We hope that you will enjoy the movie!";
                break;

            default:
                cout<<"\n WRONG OPTION";
                mainpage(a);
            }
}

For Case 2 and Case 3, these are the lines that had problems. I would like to show the whole code but the system would not let me since it has too much coding in it.

Function call for c.customer():

void customer()
{   Customer c;
    Admin a;
    int ch;
    cout<<"\nCUSTOMER PAGE";
    cout<<"\n<1> Existing Customer";
    cout<<"\n<2> Register New Customer";
    cout<<"\nEnter Your Choice : ";
    cin>>ch;
    cin.ignore();

Function call for s.shows():

void shows()
{   
        int choice,time;
        char buy;
        ifstream file("Currentlyshowing.txt", ios::in);

        if (!file.is_open()) {cout<< "error open file";}

        for(int i=0; i<=5; i++)
        {
            getline(file,moviename[i]);
        }
        for(int i=0; i<=5; i++)
        {
            for(int j=0; j<=5; j++)
            {
                file>>show[i][j];
            }
        }

Thanks in advance!

Upvotes: 0

Views: 167

Answers (1)

paddy
paddy

Reputation: 63451

Let's simplify a bit more. Interpreting your question, we have:

case 2:
    c.customer();  //<-- 'c' is not declared at this scope
    break;
case 3:
    s.shows();     //<-- 's' is not declared at this scope
    break;

But why is case 1 fine?

case 1:
    a.admin();     //<-- just fine!
    break;

Well, the identifier a was passed into the function as a parameter. As such, this value is considered in scope. In other words, it refers to a real object with a known type that is accessible by the function.

So, what does this mean about the values c and s? Probably this is one of two things:

  1. You have created objects c and s in another function and are expecting them to be visible in the function mainpage. However, they were not supplied as arguments, and because the variables are also non-global they are not visible within the function's scope.

  2. The identifiers c and s are actually typos, and you intended to use a instead.

The primary thing that the compiler is telling you is that your function has no idea what c and s are.

Upvotes: 2

Related Questions