第三节 C++-函数

本文通过一个简单的C++程序,展示了如何声明和使用函数。`WeekPlan`函数根据传入的参数输出不同的字符串,主要用到了条件判断和switch-case语句。在主函数中,调用`WeekPlan`并检查其返回值。
摘要由CSDN通过智能技术生成
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值