c++母亲生日
时间: 2023-07-01 09:20:04 浏览: 180
好的,以下是一个简单的 C++ 生日祝福程序的示例代码,您可以根据需要进行修改:
```c++
#include <iostream>
#include <string>
using namespace std;
int main() {
string mother_name;
int birth_year, birth_month, birth_day;
int current_year, current_month, current_day;
cout << "请输入您母亲的姓名:";
getline(cin, mother_name);
cout << "请输入您母亲的出生年份:";
cin >> birth_year;
cout << "请输入您母亲的出生月份:";
cin >> birth_month;
cout << "请输入您母亲的出生日期:";
cin >> birth_day;
cout << "请输入今天的年份:";
cin >> current_year;
cout << "请输入今天的月份:";
cin >> current_month;
cout << "请输入今天的日期:";
cin >> current_day;
int age = current_year - birth_year;
if (current_month < birth_month || (current_month == birth_month && current_day < birth_day)) {
age--;
}
cout << endl;
cout << "祝 " << mother_name << " 妈妈生日快乐!" << endl;
cout << endl;
cout << "今天是 " << current_year << " 年 " << current_month << " 月 " << current_day << " 日。" << endl;
cout << "您的母亲已经 " << age << " 岁了。" << endl;
return 0;
}
```
运行该程序后,会提示用户输入母亲的姓名、出生年月日以及当前日期,程序会计算出母亲的年龄并输出生日祝福信息。
阅读全文