首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

走一走,看一看,该如何解决

2012-02-17 
走一走,看一看我写了个码,希望大家看看目地是找错误和不足,大家都来指点一下,和修改意见最后希望把这个码

走一走,看一看
我写了个码,希望大家看看
目地是找错误和不足,大家都来指点一下,和修改意见
最后希望把这个码写成熟,谁能把这个问题码写的成熟可以写一下
我是新手
#include   <iostream>
#include   <string>
using   namespace   std;
int   day_total();
int   chinese_constellation();
void   days_data();
void   days_subtraion();
int   menu_select()
{

      int   c;
      char   s[80];
      cout < < "press   any   key   enter   menu......\n ";/*提示压任意键继续*/
      system( "cls ");
      cout < < "********************MENU*********************\n\n ";
      cout < < "                                 1.   查找当日是该年的第几天\n ";
      cout < < "                                 2.   查找某年n天的日期\n ";
      cout < < "                                 3.   查找某年的生肖年\n ";
      cout < < "                                 4.   输入两个日期,查找日期间的差\n ";
      cout < < "                                 5.   输入日期查询日历   \n ";
      cout < < "                                 6.   输入日期查找是星期\n ";
      cout < < "                                 7.   退出程序\n ";
      cout < < "***********************************************\n ";
      do{
            cout < < "\n                   Enter   you   choice(1~7): ";   /*提示输入选项*/

            cin> > s;   /*输入选择项*/
    c=atoi(s);

    if(c <0||c> 7||c==0)
    cout < < "                   It   is   error   number   ,Please   enter   you   choice   again~ ";
     
       
      }while(c <0||c> 7);   /*选择项不在0~11之间重输*/
     

      return   c;   /*返回选择项,主程序根据该数调用相应的函数*/
}
int   main()
{
for(;;)/*无限循环*/
      {

            switch(menu_select())       /*调用主菜单函数,返回值整数作开关语句的条件*/
            {
                  case   1:day_total();break;
                  case   2:days_data();break;
                  case   3:chinese_constellation();break;
                  case   4:days_subtraion();break;


                  case   5:cout < < "ok ";
                  case   6:cout < < "ok ";
                  case   7:cout < < "                                   **谢谢使用!再见!** " < <endl;system( "pause ");exit(0);

            }
   
      }
system( "pause ");
return   0;
}

int   day_total()
{
  int   Evenday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  int   year,day,month,nday=0,flag=1,i;
  for(;flag==1;)
  {  
    cout < < "                   enter   the   year   as   a   number: ";
    cin> > year;
    cout < < "                   enter   the   month   as   a   bumber: ";
    cin> > month;
    cout < < "                   enter   the   day   of   this   year   as   a   number: ";  
    cin> > day;
    if(((month> 2)*(year%4==0)*(year*100!=0)==0)||((month> 2)*(year%4==0)*(year%100==0)*(year%400==0)==0))
            {
      Evenday[1]=29;
              }
    //判断闰年给二月值  
    if(day> Evenday[month-1]||(year> 3000)||(year <1900)||(month> 12)||(month <1)||(year==0)||(month==0)||(day==0))
            {
      cout < < "                   it   is   error   data,   Please   enter   again: ";
      system( "pause ");  
      return   day_total();
              }
    else   flag=0;
    }
  for(i=0;i <month-1;i++)
      {
    nday+=Evenday[month-1];
      }
  nday+=day;
  cout < < "the   total   day   is   : " < <nday;
  system( "pause ");
  return   nday;

}
void   days_data()
{  
    int   Evenday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int   year,day,month,flag=1,i;
    for(;flag==1;)
  {  
    cout < < "                   enter   the   year   as   a   number: ";
    cin> > year;
    cout < < "                   enter   the   number   of   this   year: ";
    cin> > day;
   
    if((year> 3000)||(year <1900))
            {
      cout < < "                   it   is   error   data,   Please   enter   again: ";


      system( "pause ");  
      return   days_data();
              }
    else   flag=0;
    }
    for(i=0;i <12;i++)
      {

      if(day <Evenday[i+1])
      i=100;
      else
                      day-=Evenday[i];

      }
    month=i;
    cout < < "this   is   the   " < <year < < "   year   and   " < <month < < "     month   " < <day;
 
}
int   chinese_constellation()
{
string   constellation[12]={ "猴 ", "鸡 ", "狗 ", "猪 ", "兔 ", "蛇 ", "鼠 ", "龙 ", "虎 ", "牛 ", "马 ", "羊 "};
int   y,flag=1,year;
for(;flag==1;)
  {  
    cout < < "                   enter   the   year   as   a   number: ";
    cin> > year;
    if((year> 3000)||(year <1900))
            {
      cout < < "                   it   is   error   data,   Please   enter   again: ";
      system( "pause ");  
      return   chinese_constellation();
              }
    else   flag=0;
    }
    y=year%12;
      switch(y)
      {
      case   0:cout < < "                   this   constellation   is   " < <constellation[0] < <endl;break;
      case   1:cout < < "                   this   constellation   is   " < <constellation[1] < <endl;break;
      case   2:cout < < "                   this   constellation   is   " < <constellation[2] < <endl;break;
      case   3:cout < < "                   this   constellation   is   " < <constellation[3] < <endl;break;
      case   4:cout < < "                   this   constellation   is   " < <constellation[4] < <endl;break;
      case   5:cout < < "                   this   constellation   is   " < <constellation[5] < <endl;break;
      case   6:cout < < "                   this   constellation   is   " < <constellation[6] < <endl;break;
      case   7:cout < < "                   this   constellation   is   " < <constellation[7] < <endl;break;


      case   8:cout < < "                   this   constellation   is   " < <constellation[8] < <endl;break;
      case   9:cout < < "                   this   constellation   is   " < <constellation[9] < <endl;break;
      case   10:cout < < "                 this   constellation   is   " < <constellation[10] < <endl;break;
      case   11:cout < < "                 this   constellation   is   " < <constellation[11] < <endl;break;
      default:break;
      }
      return   y <11?y:-1;
}
void   days_subtraion()
{
int   max,min;
max=day_total();
min=day_total();
cout < < "the   subtration   is   : " < <((max> min)?(max-min):(min-max)) < <endl;
}

[解决办法]
在你需要滴地方加个中断 然后弹出错误提示 就ok了

热点排行