编译代码时"[Warning] extra tokens at end of"
"[Warning] extra tokens at end of" while compiling my code
我正在尝试编译并运行此代码,但没有得到预期的结果。
#include <iostream>
#include <iomanip>
#include <string>>
using namespace std;
const double uData = 45;
const double mData = 25;
const double lData = 15;
const double militaryY = 0.10;
const double militaryN = 0.00;
int main ()
{
double uData, mData, lData, subTotal, tAmount, fTotal, ssTotal, pLines;
char dataType, miitaryY, militaryN
uData = U
mData = M
lData = L
pLines >=1
if (militaryY)
{
ssTotal = (pLines + uData) * militaryY;
subTotal = ssTotal + pLines + uData
fTotal = (subTotal * tAmount) + subtotal
}
else if (militaryN)
{
subTotal = fTotal + pLines + uData
fTotal = (subTotal * tAmount) + subtotal
}
else if (militaryY)
{
ssTotal = (pLines + mData) * militaryY;
subTotal = ssTotal + pLines + mData
fTotal = (subTotal * tAmount) + subtotal
}
else if (militaryN)
{
subTotal = fTotal + pLines + mData
fTotal = (subTotal * tAmount) + subtotal
}
else if (militaryY)
{
ssTotal = (pLines + lData) * militaryY;
subTotal = ssTotal + pLines + lData
fTotal = (subTotal * tAmount) + subtotal
}
else if (militaryN)
{
subTotal = fTotal + pLines + lData
fTotal = (subTotal * tAmount) + subtotal
}
cout << "How many phone lines are there(Max 3, **Cannot enter 0**) " << pLines << " ? " << endl;
cout << "Are you active or retired military (Y or N) " << militaryY << militaryN << " ? " << endl;
cout << "What type of data plan are you using (U, M, L) " << uData << mData << lData << " ? " << endl;
cout << "Your subtotal is " << subTotal << " $ . " << endl;
system("pause");
return 0;
}
错误:
//3 18 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [警告] 指令末尾 #include 额外的标记 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp 在函数 'int main()' 中: 21 1 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] "uData"之前的预期初始值设定项 32 2 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] "else"没有前面的"if" 35 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] 在"fTotal"之前应为";" 41 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] 在"fTotal"之前应为";" 46 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] 在"fTotal"之前应为";" 52 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] 在"fTotal"之前应为";" 57 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [错误] 在"fTotal"之前应为";">
从标头中删除额外的>
:
#include <iostream>
#include <iomanip>
#include <string> // here
修复以下行:
int main ()
{
double uData, mData, lData, subTotal, tAmount, fTotal, ssTotal, pLines;
char dataType, miitaryY, militaryN; // add ; here
uData = U; // add ; here
mData = M; // add ; here
lData = L; // add ; here
pLines >=1???? // Don't know what are you trying to do.
if (militaryY)
{
ssTotal = (pLines + uData) * militaryY;
subTotal = ssTotal + pLines + uData; // add ; here
fTotal = (subTotal * tAmount) + subtotal; // add ; here
}
else if (militaryN)
{
subTotal = fTotal + pLines + uData; // add ; here
fTotal = (subTotal * tAmount) + subtotal; // add ; here
}
else if (militaryY)
{
ssTotal = (pLines + mData) * militaryY;
subTotal = ssTotal + pLines + mData; // add ; here
fTotal = (subTotal * tAmount) + subtotal; // add ; here
}
else if (militaryN)
{
subTotal = fTotal + pLines + mData; // add ; here
fTotal = (subTotal * tAmount) + subtotal; // add ; here
}
else if (militaryY)
{
ssTotal = (pLines + lData) * militaryY;
subTotal = ssTotal + pLines + lData; // add ; here
fTotal = (subTotal * tAmount) + subtotal; // add ; here
}
else if (militaryN)
{
subTotal = fTotal + pLines + lData; // add ; here
fTotal = (subTotal * tAmount) + subtotal; // add ; here
}
更新:代码的可能结构可以是:
int main ()
{
double uData, mData, lData, subTotal, tAmount, fTotal, ssTotal, pLines;
char dataType, miitaryY, militaryN;
cin >> pLines;
for (int i = 0; i < pLines; i++)
{
cin >> uData;
cin >> mData;
cin >> lData;
cin >> dataType;
if (dataType == 'Y')
{
// do something here
}
else // dataType == 'N'
{
// do something here
}
}
}
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- CMake 用于设定C++标准的设施 "at least C++NN"
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- 使用 mat.at<uchar>(i,j) 的 opencv C++中的矩阵赋值错误
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- 当键值是 std 向量时,为什么使用 at in C++ 访问映射值如此缓慢?
- 两个垫子的 OpenCV 数据是相同的,但使用 Mat::at 检索时的值已损坏
- 使用 at() 访问 std::map 元素是否比运算符 [] 慢?
- 错误:调用 .. at return 语句时没有匹配函数
- OpenCV 像素访问点与 at() - 不同的值
- C++11 功能 std::map::at 编译旧版本的C++
- AT 命令响应解析器
- 在macOS上使用libcurl库编译一个c++at项目
- 使用模板时获取"Trigger Breakpoint Error at delete"
- 为什么向量的.at()成员函数返回引用而不是迭代器
- 向量数组"Cannot access memory at address"
- 编译代码时"[Warning] extra tokens at end of"
- 重载 std::vector::at 赋值运算符