我为什么年龄不正确

基本上只是为我自己做一个项目。 基本上是编写一个简单的程序来显示您的年龄和星座。 我正在显示我想要的输出,但年龄是错误的。 我试图找出原因。我在想,因为我要减去年份。

我的生日是1991年7月14日

只是想知道如何将7月改为7。 可以肯定的是,我将不得不做很多关于星座的if和then陈述。

这是代码

#include <iostream>
#include <ctime>
#include <string>

using namespace std; 

struct Customer_info

{
    string Customer_Name;
    int Customer_Month;
    int Customer_Day;
    int Customer_Year;
};

int main()

{

Customer_info cust;



cout << "What is your name? And when exactly is your birthday?" << endl;
getline (cin, cust.Customer_Name);
cin >> cust.Customer_Month;
cin >> cust.Customer_Day;
cin >> cust.Customer_Year;

cout << "Your name is " << cust.Customer_Name << " "  << "and you were born " << cust.Customer_Month <<  endl;

time_t now = time(0);

tm *date = localtime(&now);

cout << "The date is "  << 1 + date->tm_mon << " / " <<  date->tm_mday << " / " << 1900 + date->tm_year << endl ;


int age;
age = 1900 + date-> tm_year - cust.Customer_Year;
cout << "Your age is " << age << endl; 

return 0;

}
评论