找不到标识符? [英] Identifiers not found?

查看:869
本文介绍了找不到标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个真正简单的程序中不断收到错误,我不知道为什么。帮助!

  //这个程序将计算戏剧从特定电影的收入。 
#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<< 电影标题:;
getline(cin,movieName);
cout<< 成人票出售:;
cin.ignore();
cin>> aSold;
cout<< 儿童票出售:;
cin>> cSold;

gRev =(aSold * APRICE)+(cSold * CPRICE);
nRev = gRev / 5.0;
dFee = gRev - nRev;

cout<<固定<显示点<< setprecision(2);
cout<< Movie title:<< setw(48)< movieName<< endl
cout<< 售出的成人票数:< setw(31)<< a<< endl
cout<< 售出儿童票数:<<< setw(31)< cSold<< endl
cout<< 总收入:< setw(36)< $<< setw(10)< gRev < endl
cout<< 分销商费用:< setw(34)< $<< setw(10)< dFee< endl
cout<< 净收入:< setw(38)< $<< setw(10)< nRev < endl

return 0;
}

这里是我得到的错误:



错误C2062:类型'float'意外
错误C3861:'getline':未找到标识
错误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>



也就是说,我认为你仍然会收到错误,因为 movieName code> int 。尝试将其定义为 std :: string 。您可能还想将其他变量声明为 float s,因为它们存储实数。更一般来说,我建议您根据需要定义变量,而不是在顶部。



希望这有助于!


I keep getting errors in this really simple program and I can't figure out why. Help!

//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;
}

And here are the errors I'm getting:

 error C2062: type 'float' unexpected
 error C3861: 'getline': identifier not found
 error C2065: 'CPRICE' : undeclared identifier

I've included the necessary directories, I can't understand why this isn't working.

解决方案

For your first error, I think that the problem is in this declaration:

 const float APRICE = 6.00,
       float CPRICE = 3.00;

In C++, to declare multiple constants in a line, you don't repeat the name of the type. Instead, just write

 const float APRICE = 6.00,
             CPRICE = 3.00;

This should also fix your last error, which I believe is caused by the compiler getting confused that CPRICE is a constant because of the error in your declaration.

For the second error, to use getline, you need to

#include <string>

not just

#include <cstring>

Since the getline function is in <string> (the new C++ string header) and not <cstring> (the old-style C string header).

That said, I think you'll still get errors from this, because movieName is declared as an int. Try defining it as a std::string instead. You might also want to declare your other variables as floats, since they're storing real numbers. More generally, I would suggest defining your variables as you need them, rather than all up at the top.

Hope this helps!

这篇关于找不到标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆