我正在尝试编译并运行此代码,但未获得预期的结果。
#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”之前
答案 0 :(得分:0)
从标题中删除多余的>
:
#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
}
}
}