以下是引用wjl0522在2013-7-17 18:56:53的发言:
大侠 这是我用另一台XP系统的vc6.0操作的
根据你说的 但是无法运行
呵呵,不好意思,我忘了帮你修改一下代码了,你贴上来的那些代码有点问题,你发的那些截图上显示,你的操作是没问题了,下面我把修改之后的代码给你看:大侠 这是我用另一台XP系统的vc6.0操作的
根据你说的 但是无法运行
程序代码://hotel.cpp的代码
#include <stdio.h>
#include "hotel.h"
int menu (void)
{
int code,status;
printf("\n%s%s\n",STARS,STARS);
printf("Enter the number of the desired hotl: \n");
printf("1)Faorfoe;d Ar,s 2)Hotel Olympic\n");
printf("3)Cherworthy plaza 4)The Stockton\n");
printf("5)quit\n");
printf("\n%s%s\n",STARS,STARS);
while ((status = scanf("%d",&code)) != 1 || (code <1 || code >5))
{
if (status != 1)
scanf("%*s");
printf("Enter an integer from 1 to 5,please\n");
}
return code;
}
int getnights(void)
{
int nights;
printf("How many nights are needed? ");
while (scanf("%d",&nights) != 1)
{
scanf("%*s");
printf("please enter an integer,such as 2.\n");
}
return nights;
}
void showprice (double rate,int nights)
{
int n;
double total = 0.0;
double factot = 1.0;
for (n = 1;n <= nights;n++,factot *= DISCOUNT)//你用你原来的代码与这里标记红色的代码看看,肯定不一致,这应该是你编译不通过的原因了
total += rate * factot; //字符与上面的要一致 ,你原先的那些代码应该是这里错了,你原先的代码这里是factor,而上面定义的是factot
printf("The total cost will be $%0.2f\n",total);
}
//main.cpp的代码
#include <stdio.h>
#include "hotel.h"
int main (void)
{
int nights;
double hotel_rate;
int code;
while ((code = menu()) != QUIT)
{
switch(code)
{
case 1:hotel_rate = HOTEL1;
break;
case 2:hotel_rate = HOTEL2;
break;
case 3:hotel_rate = HOTEL3;
break;
case 4:hotel_rate = HOTEL4;
break;
default:hotel_rate = 0.0;
printf("Oops!\n");
break;
}
nights = getnights();
showprice (hotel_rate,nights);
}
printf("Thank you and goodbye\n");
return 0;
}
//hotel.h的代码
#define QUIT 5
#define HOTEL1 80.00
#define HOTEL2 125.00
#define HOTEL3 155.00
#define HOTEL4 200.00
#define DISCOUNT 0.95
#define STARS "****************"
//给出选项列表
int menu (void);
//返回规定的天数
int getnights (void);
//按饭店的星级和预订的天数计算价格并显示出来
void showprice (double,int); [ 本帖最后由 love云彩 于 2013-7-17 19:07 编辑 ]

思考赐予新生,时间在于定义









