【发布时间】:2022-01-12 03:50:36
【问题描述】:
对于我的代码,我想将已完成的函数调用到 switch case 函数中。但是每当我尝试运行时,它都会显示我没有在范围内声明。
下面是我的代码:
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);
}
}
对于案例 2 和案例 3,这些是有问题的行。我想展示整个代码,但系统不让我看,因为它有太多的代码。
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();
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];
}
}
提前致谢!
【问题讨论】:
-
在询问相关问题时显示整个错误消息。
c和s的定义在哪里,您在其上调用这些成员函数customer()和shows()?你是不是真的打算在Admin类型的对象a上调用这些函数?请注意,您对mainpage的递归调用可能会导致堆栈溢出,除非编译器选择将其优化为尾递归。要打破这种情况,我需要做的就是输入“fred”作为我的选择,然后让程序崩溃或让它在繁忙循环中冻结。 -
c和s是什么? -
C:\Users\user\Desktop\try2.cpp In function 'void mainpage(Admin)': 279 5 C:\Users\user\Desktop\try2.cpp [Error] 'c' was not declared in this scope 282 11 C:\Users\user\Desktop\try2.cpp [Error] 's' was not declared in this scope@paddy 这些是错误 -
请edit your question 添加详细信息,而不是使用 cmets。阅读我的答案,根据您提供的有关代码的有限信息,我可以提供对正在发生的事情的最佳解释。
-
欢迎来到 Stack Overflow。请阅读meta.stackoverflow.com/questions/359146和stackoverflow.com/help/minimal-reproducible-example
标签: c++ scope switch-statement