S1E18生命计算器
#include <stdio.h>int main()
{
int bd_year, bd_mon, bd_day, date_year, date_mon, date_day;
char ch;
int bd, date;
int i = 0;
printf("请输入你的生日(如 1988-05-20):");
while((ch = getchar()) != '\n')
{
bd = ch;
i++;
}
// for(i = 0;i < 10;i++)
// {
// printf("%c", bd);
// }
bd_year = 1000 * (bd-'0') + 100 * (bd-'0') + 10 * (bd-'0')+ (bd-'0');
bd_mon = 10 * (bd-'0') + (bd-'0');
bd_day = 10 * (bd-'0') + (bd-'0');
printf("%d, %d, %d\n", bd_year, bd_mon, bd_day);
printf("请输入今年日期(如 2016-03-28):");
while((ch = getchar()) != '\n')
{
date = ch;
i++;
}
// for(i = 0;i < 10;i++) //???
// {
// printf("%c", date);
// }
date_year = 1000 * (date-'0') + 100 * (date-'0') + 10 * (date-'0')+ (date-'0');
date_mon = 10 * (date-'0') + (date-'0');
date_day = 10 * (date-'0') + (date-'0');
printf("%d, %d, %d\n", date_year, date_mon, date_day);
return 0;
}
请问第二个输入的年月日输出结果为什么不对?
i=0;////////////////////////////////////////////////////
while((ch = getchar()) != '\n')
{
date = ch;
i++;
} 感谢{:5_106:}
页:
[1]