一共三个文件 要求把1 2号文件放在一起编译 我把三个文件放在一个文件夹
然后打开a.c文件编译通过 点Build时出现提示无法解析的外部符号(就是2号文件内的那几个) 望指点!!! 主要是不理解怎么把1 2号文件一起编译!
1.程序名 a.c
# 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 = HOTEL1;
break;
case 3: hotel_rate = HOTEL1;
break;
case 4: hotel_rate = HOTEL1;
break;
default:hotel_rate = 0.0;
printf("oops!\n");
break;
}
nights = getnights();
showprice(hotel_rate,nights);
}
printf("thank you and goodbye.");
return 0;
}
2.程序名 hotel.c
// 9.9程序 支持模块
# 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 hotel: \n");
printf("1)fairfield arms 2)hotel olympic\n"
"3)chertworthy plaza 4)the stockton\n"
"5)退出" );
printf("%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 factor = 1.0;
for(n = 1;n <= nights;n++,factor *= DISCOUNT)
total += rate * factor;
printf("the total cost will be $%0.2f.\n",total);
}
3.程序名 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);