我不明白为什么我会收到语法错误或如何解决它

时间:2014-02-10 21:29:28

标签: c++

#include <iostream>
#include <iomanip>
#include <cmath>

const double cm_per_inch = 2.54;
const double lb_per_kg = 2.20462262;

using namespace std;

int main ()
{
    int lucky,m,d,y;
    double h_in,w_lb,h_cm,w_kg;
cout << "Zelda's Lucky Number Calculator" << endl 
    << "Enter the month of your birthday in numerical form:" ;
cin >> m;
cout << "Enter the date of your birthday:" ;
cin >> d;
cout << "Enter the year of your birthday:" ;
cin >> y;
cout << "Enter your height in inches:" ;
cin >> h_in;
cout << "Enter your weight in pounds:" ;
cin >> w_lb;
//Convert height into cm and weight into kg
h_cm = h_in*cm_per_inch;
w_kg = w_lb/lb_per_kg;
//Calculate lucky number
lucky = static_cast<int>(((static_cast<double>(m) 100*pow(m,2) + 10*pow(d,3))/y+      (sqrt(pow(w_kg,6)/h_cm))))  % 10 + 1;
//Display lucky number
cout << "Your lucky number is " <<lucky<< ". Thank you, that will be $25." << endl ;
return 0;
}

我得到的错误是:

  

c:\ users \ fields \ desktop \ school \ cse 100 \ lab3 \ soumishyrkas_lab3.cpp(35):错误C2143:语法错误:缺少')''常数'之前
  c:\ users \ fields \ desktop \ school \ cse 100 \ lab3 \ soumishyrkas_lab3.cpp(35):错误C2143:语法错误:缺少'('在'常数'之前'   c:\ users \ fields \ desktop \ school \ cse 100 \ lab3 \ soumishyrkas_lab3.cpp(35):错误C2059:语法错误:')'

1 个答案:

答案 0 :(得分:7)

static_cast<double>(m) 100

你在这里错过了某种类型的运营商。您不能只在整数字符旁边有一个static_cast。我不知道你的确切公式是什么,但我假设那里应该有一个+