"else" DevC++ 之前的预期主表达式

Expected primary expression before "else" DevC++

本文关键字:表达式 else DevC++      更新时间:2023-10-16

我得到错误"预期的主表达式之前"else"在这部分代码。然而,我找不到解决办法。如有任何帮助,我将不胜感激。

//create class Date object today
Date today (monthT, dayT, yearT);
// check today date that it is correct
if(!(today.checkDate(monthT, dayT, yearT)))
cout << "Today's date is wrong!" << endl;
return 0;
else
//increment date to get tomorrow
cout << "Tomorrow is " << monthT << ", " << dayT+1 << ", " << yearT << "." << endl; 

您错过了大括号:

//create class Date object today
Date today (monthT, dayT, yearT);
// check today date that it is correct
if(!(today.checkDate(monthT, dayT, yearT))) { //<---
    cout << "Today's date is wrong!" << endl;
    return 0;
} else //<---
//increment date to get tomorrow
    cout << "Tomorrow is " << monthT << ", " << dayT+1 << ", " << yearT << "." << endl;