C 编程错误|未申报的标识符
C++ Programming Error | Undeclared Identifier
所以我正在尝试制作一个简单的程序,并且我不断获得'未宣布的标识符错误',用我的名字,作者,价格,价格,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;
}
您试图通过用comma ,
分离错误来声明不同类型的多个局部变量,这是错误的。使用单独的语句来声明您的变量,然后使用分号;
。分号标志着陈述的结尾:
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::getline(std::cin, author);
相关文章:
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 有一个打印语句的函数是一种糟糕的编程实践吗
- #ifdef和未声明的标识符
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- f2、f3、f4标识符未找到
- 模板元编程:如何将参数包组合成新的参数包
- Qt Q串行端口未编程设备未关闭
- 设置 Visual Studio for MPI: 找不到标识符错误
- 未声明的标识符编译暗黑破坏神 2 程序"muleview"
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 模板元编程 - 尝试实现维度分析
- 我是编程新手
- 如何让 GCC/Clang 在保留标识符上出错
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 使用说明符 extern 声明的C++中的标识符链接
- C++:枚举:错误:应使用标识符而不是"}"
- 为什么我们不能重复使用具有不同模板参数的别名模板标识符?
- C 编程错误|未申报的标识符