Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;编程错误|未声明的标识符_C++_Visual Studio_Compiler Errors - Fatal编程技术网

C++ C++;编程错误|未声明的标识符

C++ C++;编程错误|未声明的标识符,c++,visual-studio,compiler-errors,C++,Visual Studio,Compiler Errors,因此,我正在尝试制作一个简单的程序,我在控制台中不断得到一个“未声明的标识符错误”,上面有我的姓名、作者、价格、isbn、数量、第一个结果和第二个结果。我很抱歉,如果这种类型的问题已经被问到,但我还没有能够解决它 这是我的节目: #include <iostream> #include <string> using namespace std; int main() { string name, author, double isbn,

因此,我正在尝试制作一个简单的程序,我在控制台中不断得到一个“未声明的标识符错误”,上面有我的姓名、作者、价格、isbn、数量、第一个结果和第二个结果。我很抱歉,如果这种类型的问题已经被问到,但我还没有能够解决它

这是我的节目:

#include <iostream>
#include <string>
using namespace std;

int main()

{
    string name, author,
        double isbn,
        float price,
        int quantity,
        float firstresult,
        float secondresult,
        const float tax (0.07);

    cout << "What is the name of the book?";
    cin >> name;
    cout << "What is the authors name?";
    cin >> author;
    cout << "What is the ISBN number?";
    cin >> isbn;
    cout << "What is the price?";
    cin >> price;
    cout << "How many books did you purchase?";
    cin >> quantity;

    firstresult = price*tax;
    secondresult = price + firstresult;

    if (quantity > 5) {
        secondresult += (quantity - 5) * 2.00;
    }

    cout << "------------------------" << endl;
    cout << "Invoice of Order:" << endl;
    cout << name << endl;
    cout << author << endl;
    cout << isbn << endl;
    cout << price << endl;
    cout << quantity << endl;
    cout << "Total Cost: " << secondresult << endl;
    cout << "------------------------" << endl;

    return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
字符串名称、作者、,
双isbn,
浮动价格,
整数数量,
浮动第一个结果,
第二个结果,
固定浮动税(0.07);
姓名;
作者;
cout>isbn;
价格;
数量;
firstresult=价格*税费;
第二个结果=价格+第一个结果;
如果(数量>5){
第二个结果+=(数量-5)*2.00;
}

cout您试图用逗号分隔多个不同类型的局部变量,这是错误的。
。请使用单独的语句声明变量,并使用分号
。分号标记语句的结尾:

string name, author; // you are defining multiple variables of the same type which is fine
double isbn;
float price;
int quantity;
float firstresult;
float secondresult;
const float tax (0.07);
这些不是函数参数,在这种情况下,它们将用逗号分隔。也就是说,当从标准输入中接受字符串时,应使用:

std::getline(std::cin, author);

您不能在同一行中定义不同类型的变量。您需要分号,而不是在声明所有这些变量的main顶部每行末尾的逗号。clang的错误消息非常清楚问题所在:对于
std::string
输入,您应该使用
std::getline(std::cin,stringVariable)
您应该将
string
变量定义为空字符串
variable=”“
。非常感谢Ron,我非常感谢!