- 分享
- 0
- 人气
- 0
- 主题
- 26
- 帖子
- 103
- UID
- 480553
- 积分
- 154
- 阅读权限
- 13
- 注册时间
- 2012-3-15
- 最后登录
- 2017-4-13
- 在线时间
- 921 小时
|
请问各位大神
有没有办法让function definition return 2个value?
因为在 printf("\n Total room charges : RM%.2lf",roomCharges);那一排原本应该是 total room charges for %.0lf : RM%.2lf , i,roomCharges.
有没有办法把i也return回来呢?
这是c programming
#include<stdio.h>
float calculateCharges (char);
int main()
{
char roomCode;
double roomCharges,r=0.00;
printf("\t\tSeri Anjung Motel\n\n");
printf(" Room Code\tRoom Type\tRoom Rate (RM)\n");
printf(" =========\t=========\t==============\n");
printf(" A\t\tExecutive\t 560.00\n");
printf(" B\t\tSuite\t\t 451.60\n");
printf(" C\t\tDeluxe\t\t 334.50\n");
printf(" D\t\tSuperior\t 245.80\n\n");
r++;
printf("\n %.0lf. Enter room code(A/B/C/D or X to end):",r);
scanf(" %c", &roomCode);
roomCharges=calculateCharges(roomCode);
printf("\n Total room charges : RM%.2lf",roomCharges);
scanf(" %c", &roomCode);
}
float calculateCharges (char roomCode)
{
char Breakfast;
double total=0.00, additionPerson=0.00, RoomRate=0.00, rc=0.00,i=0.00,r=1.00;
while(roomCode != 'X' && roomCode != 'x' ){
if(roomCode == 'A' || roomCode == 'a')
RoomRate = 560.00;
else
if(roomCode == 'B' || roomCode == 'b')
RoomRate = 451.60;
else
if(roomCode == 'C' || roomCode == 'c')
RoomRate = 334.50;
else
if(roomCode == 'D' || roomCode == 'd')
RoomRate = 245.80;
printf(" Additional breakfast(Y/N):");
scanf(" %c", &Breakfast);
if(Breakfast=='Y' || Breakfast=='y')
{
printf(" Number of additional person(s):");
scanf(" %lf", &additionPerson);
total = (additionPerson*20)+RoomRate; }
else if(Breakfast=='N' || Breakfast =='n')
total=RoomRate;
printf("\n Room charges : Rm%.2lf\n",total);
rc=rc+total;
r++;
printf("\n %.0lf. Enter room code(A/B/C/D or X to end):",r);
scanf(" %c", &roomCode);
i++;
}
return rc;
} |
|