gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:27:38 24 4
gpt4 key购买 nike

我在这部分代码中收到错误“expected primary-expression before “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;

关于c++ - "else"DevC++ 之前的预期主表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24226166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com