编译我的代码时出现“[Warning] extra tokens at end”

"[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 [Warning] extra tokens at end of #include directive //C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp In function 'int main()': //21 1 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] expected initializer before 'uData' //32 2 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] 'else' without a previous 'if' //35 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] expected ';' before 'fTotal' //41 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] expected ';' before 'fTotal' //46 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] expected ';' before 'fTotal' //52 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] expected ';' before 'fTotal' //57 3 C:\Users\adamp\Desktop\DevCppFiles\Project 4\Powers4.cpp [Error] expected ';' before 'fTotal'

从 header 中删除多余的 >:

#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           
        }
    }


}