include <iostream> //header file
using namespace std; // use namespace
int main()
{
int ret = 0;
int Today = 0;
int WeekPlan(int day); //function declaration
Today = 2;
ret = WeekPlan(Today); //call function
if (ret) { //check the return value
cout << "time invaild, input value " << Today << endl; //output info when function call
}
return 0;
}
/*function definiton*/
int WeekPlan(int Day)
{
int ret = 0;
if (!Day) {
ret = 1;
return ret;
}
switch(Day) {
case 1: cout << "aaaa" << endl;
break;
case 2: cout << "bbbb" << endl;
break;
default: cout << "zzzz" <<endl;
break;
}
return ret;
}
第三节 C++-函数
本文通过一个简单的C++程序,展示了如何声明和使用函数。`WeekPlan`函数根据传入的参数输出不同的字符串,主要用到了条件判断和switch-case语句。在主函数中,调用`WeekPlan`并检查其返回值。
摘要由CSDN通过智能技术生成