【发布时间】:2012-02-22 14:46:45
【问题描述】:
我必须编写一个程序来询问用户是男性还是女性,然后是生日(mm dd yyyy),然后是日期。然后计算保险物品的年龄,该保险物品用于 if else 循环以告诉用户他们将支付的价格。这是我的代码:
#include<stdio.h>
#include<conio.h>
char* calculateAge(int month, int day, int year, int birthmonth, int birthday, int birthyear, char gender)
{
int temp;
temp = (year - birthyear);
if (temp >= 33 && <= 62 && gender == 'm' || temp >= 30 && <= 62 && gender == 'f') {
return "The rate class is: Best rate - $40.00 per day or $200.00 per week.";
} else if (temp >= 25 && <= 29 && gender == 'f') {
return "The rate class is: Risk rate 1 - Best rate plus $10.00 per day or best rate plus $55.00 per week.";
} else if (temp >= 25 && <= 32 && gender == 'm') {
return "The rate class is: Risk rate 1 - Risk rate 1 plus $7.00 per day or risk rate 1 plus $30.00 per week.";
} else if (temp >= 66 && gender == 'm' || temp >= 63 && gender == 'f') {
return "The rate class is: Best rate plus $2.00 for each year over age 66 (male) or 63 (female), per day or best rate plus $5.00 for each year over age 66 (male) or 63 (female), per week."
} else {
return "Sorry, the renter is not 25 years of age or older.";
}
}
void main() {
int month, day, year, birthmonth, birthday, birthyear;
char gender;
printf("\nWelcome to the car renter’s rate finder. " );
printf("\nPlease enter today's date (mm dd yyyy): ");
scanf("%d%d%d",&month, &day, &year);
printf("\nPlease enter the renter’s gender (m/f):" );
scanf("%c", &gender);
printf("\nPlease enter the renter’s date of birth (mm dd yyyy):");
scanf("%d%d%d", &birthmonth, &birthday, &birthyear);
printf("\n Thank you.");
printf("%s", calculateAge(month, day, year, birthmonth, birthday, birthyear, gender));
return 0;
}
我不断收到这些错误,说: 第 14 行:错误:'
我不明白这些错误,有人可以帮我让这个编程工作吗?这是它应该有的输出:
Welcome to the car renter’s rate finder.
Please enter today’s date (mm dd yyyy): 1 23 2008
Please enter the renter’s gender (m/f): m
Please enter the renter’s date of birth (mm dd yyyy): 6 9 1983
Thank you.
Sorry, the renter is not 25 years of age or older.
Welcome to the car renter’s rate finder.
Please enter today’s date (mm dd yyyy): 1 23 2008
Please enter the renter’s gender (m/f): f
Please enter the renter’s date of birth (mm dd yyyy): 2 23 1980
Thank you.
The female renter is 27 years old.
The rate class is: Risk rate 1 - $50.00 per day or $255.00 per week.
【问题讨论】:
标签: c function compiler-construction methods if-statement