我正在尝试编译并运行此代码,但没有得到预期的结果。
#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
}
}
}