当前位置: 代码迷 >> C语言 >> 大哥们,帮帮忙,在线等!!!谢谢
  详细解决方案

大哥们,帮帮忙,在线等!!!谢谢

热度:567   发布时间:2008-03-27 13:43:18.0
大哥们,帮帮忙,在线等!!!谢谢
下面是我的程序,是可以运行的,但是有错误.
第1,如果我第1行输入a,第2行也输入a或者其他字母,没有beep的声音出来!!
第2,如果我第一行输入a,第2行输入10或者其他数字.程序运行了,然后再从第一行输入a,第2行输入a或者其他字母,效果应该是不运行而且发出beep一声,但是程序自动加10了.
大哥们,帮帮忙,在线等!!!谢谢
Description :  The program should accept ONLY UPPER/lower Case characters A-H
                   (or a-h) as well as R and Q (or r and q). All other user input for   choice
                        should cause an AUDIBLE BEEP, and not be accepted. If the user enters
                        a letter (Upper or Lower case) from A-H (or a-h),  it should then prompt   
                        the user for the number of POUNDS. Pounds should be a floating point   
                   value. Negative values for POUNDS should cause an AUDIBLE BEEP   
                        and not be accepted.
                       
                         When the user chooses to Quit, the program should display a message and
                         ask the user to hit any key to continue before ending the program.                 
*/

//      INCLUDE SECTION
#include <stdio.h>        // used for printf, scanf, getchar, puts
#include <conio.h>      // used for getch
#include <stdlib.h>      // used for system

//       DEFINE SECTION
#define A "Smarties"
#define A_P 4.55
#define B "Flour"
#define B_P 1.5
#define C "Soup"
#define C_P 2.88
#define D "Walnuts"
#define D_P 5.25
#define E "Rice "
#define E_P 1.05
#define F "Noodles"
#define F_P 0.35
#define G "Sugar"
#define G_P 0.92
#define H "CakeMix "
#define H_P 1.45

/*      FUNCTION PROTOTYPE SECTION,show the item(such as price,pounds,
        total pounds,total price,average pounds and so on) and input the letter
*/

char menu(float a,float b,float c,float d,float e,float f,float g,float h,
                  float pounds1,float pounds2,float pounds3,float pounds4,
                  float pounds5,float pounds6,float pounds7,float pounds8,
                  float subtotal1,float subtotal2,float subtotal3,float subtotal4,
                  float subtotal5,float subtotal6,float subtotal7,float subtotal8,
                  float tpounds,float avgcosts,float total);
main()
{
        //Variable declarations
        char gamble;
        float pounds1,pounds2,pounds3,pounds4,pounds5,pounds6,pounds7,pounds8;
        float tpounds,avgcosts,total;
        float subtotal1,subtotal2,subtotal3,subtotal4;
        float subtotal5,subtotal6,subtotal7,subtotal8;
        float a=A_P,b=B_P,c=C_P,d=D_P,e=E_P,f=F_P,g=G_P,h=H_P;
        //float aaa,aa;
        do
        {
          // clean the screem
          system("cls");

          // definition the vale
          tpounds=0, avgcosts=0,total=0;
          subtotal1=0,subtotal2=0,subtotal3=0,subtotal4=0;
          subtotal5=0,subtotal6=0,subtotal7=0,subtotal8=0;
          pounds1=0,pounds2=0,pounds3=0,pounds4=0,pounds5=0;
          pounds6=0,pounds7=0,pounds8=0;
          gamble=menu(a,b,c,d,e,f,g,h,pounds1,pounds2,pounds3,pounds4,pounds5,
                                  pounds6,pounds7,pounds8,subtotal1,subtotal2,subtotal3,
                                  subtotal4,subtotal5,subtotal6,subtotal7,subtotal8,tpounds,
                                  avgcosts,total);

          //estimate true or false
          while(gamble!='R'&&gamble!='r'&&gamble!='Q'&&gamble!='q')
          {
          switch(gamble)
          {

                case 'a':
                case 'A': float aaa,aa;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  scanf("%f",&aa);
                                  getchar();
                                  aaa=aa;
                                  fflush(stdin);
                                  if(aaa>=0)
                                  {
                                   aaa=aa;pounds1=aaa+pounds1,subtotal1=pounds1*a;
                                   tpounds=tpounds+aaa;total=total+aaa*a;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'b':
                case 'B': float bb,bbb;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  fflush(stdin);
                                  scanf("%f",&bb);
                                  if(bb>=0)
                                  {
                                   bbb=bb;pounds2=bbb+pounds2,subtotal2=pounds2*b;
                                   tpounds=tpounds+bbb;total=total+bbb*b;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'c':
                case 'C': float cc,ccc;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  fflush(stdin);
                                  scanf("%f",&cc);
                                  if(cc>=0)
                                  {
                                   ccc=cc;pounds3=ccc+pounds3,subtotal3=pounds3*c;
                                   tpounds=tpounds+ccc;total=total+ccc*c;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'd':
                case 'D': float dd,ddd;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  fflush(stdin);
                                  scanf("%f",&dd);
                                  if(dd>=0)
                                  {
                                   ddd=dd;pounds4=ddd+pounds4,subtotal4=pounds4*d;
                                   tpounds=tpounds+ddd;total=total+ddd*d;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'e':
                case 'E': float ee,eee;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  fflush(stdin);
                                  scanf("%f",&ee);
                                  if(ee>=0)
                                  {
                                   eee=ee;pounds5=eee+pounds5,subtotal5=pounds5*e;
                                   tpounds=tpounds+eee;total=total+eee*e;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'f':
                case 'F': float ff,fff;
                                  printf("\n\n\t\t   Please input your number ==>");
                                  fflush(stdin);
                                  scanf("%f",&ff);
                                  if(ff>=0)
                                  {
                                   fff=ff;pounds6=fff+pounds6,subtotal6=pounds6*f;
                                   tpounds=tpounds+fff;total=total+fff*f;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'g':
                case 'G': float gg,ggg;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  fflush(stdin);
                                  scanf("%f",&gg);
                                  if(gg>=0)
                                  {
                                   ggg=gg;pounds7=ggg+pounds7,subtotal7=pounds7*g;
                                   tpounds=tpounds+ggg;total=total+ggg*g;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                case 'h':
                case 'H': float hh,hhh;
                                  printf("\n\n\t\t   Please input your number ==> ");
                                  fflush(stdin);
                                  scanf("%f",&hh);
                                  if(hh>=0)
                                  {
                                   hhh=hh;pounds8=hhh+pounds8,subtotal8=pounds8*h;
                                   tpounds=tpounds+hhh;total=total+hhh*h;
                                   avgcosts=total/tpounds;
                                   }
                                   else
                                  {
                                        printf("\a");
                                  }
                                   break;

                default: printf("\a");

                                  }
           system("cls");   //clean the screem
           gamble=menu(a,b,c,d,e,f,g,h,pounds1,pounds2,pounds3,pounds4,pounds5,
                                   pounds6,pounds7,pounds8,subtotal1,subtotal2,subtotal3,
                                   subtotal4,subtotal5,subtotal6,subtotal7,subtotal8,tpounds,
                                   avgcosts,total);
          }
   }
        while(gamble!='Q'&&gamble!='q');   //estimate true or false
        system("cls");       //clean the screem
        printf("HIT ANY KEY TO CONTINUE ...");
        getch();
}
char menu(float a,float b,float c,float d,float e,float f,float g,float h,
                  float pounds1,float pounds2,float pounds3,float pounds4,
                  float pounds5,float pounds6,float pounds7,float pounds8,
                  float subtotal1,float subtotal2,float subtotal3,float subtotal4,
                  float subtotal5,float subtotal6,float subtotal7,float subtotal8,
                  float tpounds,float avgcosts,float total)
{
   char soccer;
   printf("\n\t\t\tBULK FOOD STORE PROGRAM");
   printf("\n\n    Item\tDescription\tCost/lb\t\t#Pounds\t\tSubtotal\n");
   printf("\n\n\      A\t\t"A"\t%4.2f\t\t%4.2f\t\t$%7.2f",a,pounds1,subtotal1);
   printf("\n      B\t\t"B"\t\t%4.2f\t\t%4.2f\t\t$%7.2f",b,pounds2,subtotal2);
   printf("\n      C\t\t"C"\t\t%4.2f\t\t%4.2f\t\t$%7.2f",c,pounds3,subtotal3);
   printf("\n      D\t\t"D"\t\t%4.2f\t\t%4.2f\t\t$%7.2f",d,pounds4,subtotal4);
   printf("\n      E\t\t"E"\t\t%4.2f\t\t%4.2f\t\t$%7.2f",e,pounds5,subtotal5);
   printf("\n      F\t\t"F"\t\t%4.2f\t\t%4.2f\t\t$%7.2f",f,pounds6,subtotal6);
   printf("\n      G\t\t"G"\t\t%4.2f\t\t%4.2f\t\t$%7.2f",g,pounds7,subtotal7);
   printf("\n      H\t\t"H"\t%4.2f\t\t%4.2f\t\t$%7.2f",h,pounds8,subtotal8);
   printf("\n\n\ttotal pounds =%7.2f\t\t\tSUBTOTAL\t$%7.2f",tpounds,total);
   printf("\n\tAvg Cost/lb  =%7.2f\t\t\tGST Amount\t$%7.2f",avgcosts,total*.008);
   printf("\t\t\t\t\t\t\tPST Amount\t$%7.2f",total*.005);
   printf("\n\n\t\t\t\t\t\tTOTAL Amount\t$%7.2f",total*.005+total*.008+total);
   printf("\n\n\tYour choice (R to RESET, Q to quit) ==> ");
   fflush(stdin);      //clean the buffer
   scanf("%c",&soccer);
   getchar();    //input a number
   fflush(stdin);
   return(soccer);
}
搜索更多相关的解决方案: ONLY  beep  The  数字  字母  

----------------解决方案--------------------------------------------------------
你的程序的目的不是很明确啊,我不太懂你什么意思
----------------解决方案--------------------------------------------------------
看不懂

再修改下
----------------解决方案--------------------------------------------------------
删去case 'A': 中scanf("%f",&aa); 后的 getchar(); 可以解决LZ所讲的问题了,测试通过。
----------------解决方案--------------------------------------------------------
如果我第一行输入a,第2行输入10或者其他数字.程序运行了,然后再从第一行输入a,第2行输入a或者其他字母,效果应该是不运行而且发出beep一声,但是程序也自动加10了.
----------------解决方案--------------------------------------------------------
  相关解决方案