C ++错误表达式不能用作函数

时间:2014-09-21 23:14:19

标签: c++

如何编辑

的公式
weekday=(day+2(month)+3(month)/5+year+year/4-year/100+year/400)/7

这样我就不会收到错误消息,说“表达式不能用作函数”?

#include <iostream>
using namespace std;
int main()
{
int date=0;
int month=0;
int day=0;
int year=0;
int leftover=0;
int weekday=0;

cout<<"Enter Date (ex.20140912) :";
cin>>date;

year=date/10000;
leftover=date%10000;
month=leftover/100;
day=date%100;
{
if (month==3)
    {cout<<"March "<< day<<", "<< year<<":";
        weekday=(day+2(month)+3(month)/5+year+year/4-year/100+year/400)/7;

            if (weekday==0)
                {cout<<"Saturday";
                }
            if (weekday==1)
                {cout<<"Sunday";
                }
            if (weekday==2)
                {cout<<"Monday";
                }
            if (weekday==3)
                {cout<<"Tuesday";
                }
            if (weekday==4)
                {cout<<"Wednesday";
                }

2 个答案:

答案 0 :(得分:3)

代码2(month)是函数调用语法,好像2是一个函数......但事实并非如此。你是否意味着乘法,例如2 * month

答案 1 :(得分:3)

您需要输入运算符(*)进行乘法运算:

weekday=(day+2*(month)+3*(month)/5+year+year/4-year/100+year/400)/7;

如果操作符丢失,则c(++)将其解释为函数调用,其中函数名称为例如2