当前位置: 代码迷 >> C语言 >> 这个程序错在了那里.
  详细解决方案

这个程序错在了那里.

热度:310   发布时间:2006-05-11 00:21:00.0
这个程序错在了那里.

#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.");
}



#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");
printf("3) Chertworthy Plaza 4) The Stockton\n");
printf("5) quit\n");
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);
}


#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(void);


----------------解决方案--------------------------------------------------------
我有一个很大程序有一个非常隐蔽的错误,程序没有任何注释,让你找,你找吗
----------------解决方案--------------------------------------------------------

答: 打死我也不找~!

并不是我挑剔,你至少写点注释,别人帮你,没必要揣摩你的心思
这样去看你的程序,比写一个还花时间


----------------解决方案--------------------------------------------------------
  相关解决方案