简体   繁体   English

C++ 程序菜单混乱

[英]C++ Program Menu Confusion

In this C++ program, I keep getting an error that says "editor placeholder in source file" for case 'fa': findArea.在这个 C++ 程序中,我不断收到一条错误消息,指出“fa”案例“源文件中的编辑器占位符”:findArea。 I do not know what the problem is.我不知道问题是什么。 I have tried to change it up to another name but haven't succeeded.我试图将其更改为另一个名称,但没有成功。

int main () 
{ 
 void findArea(double);
 void quit();
 void printHelp();

 case 'h':
 case 'H': printHelp(); //help text.
 break;

 case 'q':
 case 'Q': quit();  //quit program.
 break;

 case 'fa':
 case 'FA': findArea(); //find area of rectangle.
 break;
 }
 void quit(){ // end program
 cout << "Ending!"  << endl;
 }
 void printHelp(){ // help text

 cout << "Supported commands: \n"
       << "fa. find area./n"
       << "h. print help./n"
       << "q. quit./n"    
   }
 void findArea(){
  area = length * width;
 }
  1. You have你有
 void findArea(double);
 void quit();
 void printHelp();

inside of your main function.在您的主要 function 内部。 Normally these would be outside of any function.通常这些将在任何 function 之外。

  1. void findArea(double); is declared, but case 'FA': findArea();已声明,但case 'FA': findArea(); is used and void findArea(){} is defined.使用并定义void findArea(){} Change:改变:
void findArea(double);

to

void findArea();

Try this code .试试这个代码
Prob your code had :可能你的代码有
You had function declaration in main() which is not allowed.您在 main() 中有 function 声明,这是不允许的。 There was one more mistake you had argument type double in area but in function body of area it was void so it is a argument mismatch compiler error.还有一个错误,您的参数类型为 double 区域,但在 function 区域主体中它是无效的,因此这是一个参数不匹配编译器错误。
Also your code has case statement without switch().您的代码也有没有 switch() 的 case 语句。 there are lot more errors like you had not declared variables not even taking input.还有更多错误,例如您没有声明变量甚至没有接受输入。

   #include<iostream>
   using namespace std;
  void findArea();
  void printHelp();
  void quit();
  int main ()
  { 
      char ch; 
      cout<<"Enter choice \n";
      cout<<"h for Help \n";
     cout<<"q for Quit \n"; 
    cout<<"fa to find area \n"; 
     cin>>ch;
      switch (ch)
      {
     case 'h':
    case 'H': printHelp(); //help text. 
                    break;
      case 'q':
       case 'Q': quit(); //quit program.
                      break; 
      case 'f':  
      case 'F':       findArea(); 
                           break;
      } 
 return 0;
  }
  void quit()
  { 
    cout << "Ending!" << endl;
  }  
   void printHelp()
   {
  // help text
 cout << "Supported commands: \n"; 
  cout<< "f. find area.\n" ;
 cout<< "h. print help.\n" ;
 cout<< "q. quit./n" ;
  } 
  void findArea()
  { 
   double l,w,area;
   cout<<"Enter Length \n";     
   cin>>l;
   cout<<"Enter Width \n";
   cin>>b;

   area = l * w; 
   cout<<"\n\tArea = "<<area;
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM