找不到标识符
Identifiers not found?
我在这个非常简单的程序中不断地出错,我不知道为什么。帮助
//This program will calculate a theater's revenue from a specific movie.
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
int main ()
{
const float APRICE = 6.00,
float CPRICE = 3.00;
int movieName,
aSold,
cSold,
gRev,
nRev,
dFee;
cout << "Movie title: ";
getline(cin, movieName);
cout << "Adult tickets sold: ";
cin.ignore();
cin >> aSold;
cout << "Child tickets sold: ";
cin >> cSold;
gRev = (aSold * APRICE) + (cSold * CPRICE);
nRev = gRev/5.0;
dFee = gRev - nRev;
cout << fixed << showpoint << setprecision(2);
cout << "Movie title:" << setw(48) << movieName << endl;
cout << "Number of adult tickets sold:" << setw(31) << aSold << endl;
cout << "Number of child tickets sold:" <<setw(31) << cSold << endl;
cout << "Gross revenue:" << setw(36) << "$" << setw(10) << gRev << endl;
cout << "Distributor fee:" << setw(34) << "$" << setw(10) << dFee << endl;
cout << "Net revenue:" << setw(38) << "$" << setw(10) << nRev << endl;
return 0;
}
以下是我得到的错误:
error C2062: type 'float' unexpected
error C3861: 'getline': identifier not found
error C2065: 'CPRICE' : undeclared identifier
我已经包含了必要的目录,我不明白为什么这不起作用。
对于您的第一个错误,我认为问题出在这个声明中:
const float APRICE = 6.00,
float CPRICE = 3.00;
在C++中,要在一行中声明多个常量,不需要重复类型的名称。相反,只需编写
const float APRICE = 6.00,
CPRICE = 3.00;
这也应该修复您的上一个错误,我认为这是由于编译器由于您声明中的错误而混淆CPRICE
是常量所导致的。
对于第二个错误,要使用getline
,您需要
#include <string>
不仅仅是
#include <cstring>
由于getline
函数在<string>
(新C++字符串标头)中,而不是<cstring>
(旧式C字符串标头)。
也就是说,我认为您仍然会从中得到错误,因为movieName
被声明为int
。请尝试将其定义为std::string
。您可能还想将其他变量声明为float
s,因为它们存储的是实数。更普遍地说,我建议根据需要定义变量,而不是全部放在顶部。
希望这能有所帮助!
相关文章:
- 设置 Visual Studio for MPI: 找不到标识符错误
- 找不到标识符合并
- 在 c++ 中找不到此函数的标识符
- 从子类访问模板类成员时出现"找不到标识符"错误
- std::p opcount 标识符在 MSVC 16.6.0 中找不到
- OpenCV 3 错误"CV_FOURCC":找不到标识符
- C++ ATL | 找不到_InternalQueryInterface标识符
- im调用函数时找不到标识符?
- clock_gettime:在 Windows 10 的 Visual Studio 中找不到标识符
- 英特尔 TBB - "初始化关键部分 Ex":找不到标识符编译器错误
- 找不到标识符.C3861
- 找不到睡眠标识符 Visual Studio 2017
- 在void tryagain()上找不到标识符
- 找不到内存集标识符
- 在C 类中找不到标识符
- 找不到标识符,尝试在 C++ 中显示数组值
- 找不到QT 5.6 update()函数标识符
- 我遇到:错误2错误C3861:"fx":找不到标识符
- 找不到加载着色器标识符
- OpenGL - 'glTexSubImage3D':找不到标识符