瑞星卡卡安全论坛

首页 » 技术交流区 » 系统软件 » 会C语言的进来~~~~~~~~~~~~~~~~~~
摩天大侠 - 2006-11-19 10:45:00
1.某市不同车牌的出租车3KM的起步价和计费分别为:夏利7元  3KM以外2.1元/KM
                                              富康8元  3KM以外2.4元/KM
                                            桑塔纳9元  3KM以外2.7元/KM
编程实现:从键盘输入乘车的车型既及行车的公里数,输出应付车资



用C语言编哦!!!!!!!!!!!!!!!!!!!!!!!
梅塞德斯 - 2006-11-19 17:35:00
北京的费用是无论什么车都2元/KM

伊蓝特、索纳塔、三厢富康、捷达

贵啊



反正都一个价所以我们都打伊蓝特、索纳塔经常看到空驶的三厢富康、捷达


楼主抱歉,我好象跑题了
海蓝云天 - 2006-11-19 17:55:00
自己的事情自己做.........
朱晓磊 - 2006-11-20 10:12:00
这个程序不难,楼主自己想想吧

学编程就要勤动手
不懂就要问 - 2006-11-22 5:01:00
看不懂啥意思```- =!
天下奇才 - 2006-11-22 18:09:00
简单点,就是一个switch能够解决的问题。想复杂一些,完全可以做一个结构体,不难
wuyue5510 - 2006-11-23 13:44:00
楼主要好好学习啊,
闪电风暴 - 2006-11-23 19:16:00
晕倒,学两个星期就可以会的啊。希望楼主自学
Meight - 2006-12-9 12:14:00
太简单啦
不屑于编
用switch和if语句就可以实现啦
翹翹鈑oоО - 2006-12-9 14:43:00
用switch语句吗?
病毒是傻鸟 - 2006-12-12 15:57:00
含有switch  但是存在着调用啊
天下奇才 - 2006-12-13 18:15:00
引用:
【病毒是傻鸟的贴子】含有switch  但是存在着调用啊
………………

可以不用调用任何函数,虽然这样的结构不好,但是对于初学者,我们不可能要求他们拥有更多的意识
先学语法后学技术,然后再学思想
storysnail - 2006-12-15 13:46:00
/***************************************************************************
*  如果你发现错误,请指教!
*            car.c
*
*  Fri Dec  15 14:16:49 2006
*  Copyright  2006  Elliot
*  storysnail@gawab.com
****************************************************************************/

/*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   
    Compile:
      gcc car.c -o car

某市不同车牌的出租车3KM的起步价和计费分别为:
夏利7元 3KM以外2.1元/KM
富康8元 3KM以外2.4元/KM
桑塔纳9元 3KM以外2.7元/KM
编程实现:从键盘输入乘车的车型既及行车的公里数,输出应付车资
*/

#include <stdio.h>
#include <string.h>

/* defines*/
#define XIALI_ID1
#define FUKANG_ID2
#define SANGTANA_ID3
#define UNDEFINED_ID0



/***************************************************************************************
Displays the proper usage
***************************************************************************************/
void DisplayProperUsage(FILE * pFile)
{
fprintf(pFile, "Proper Usage: [car] [Car modes] [Kilometres]\n\n");

fprintf(pFile, "Car modes: \n");
fprintf(pFile, "    XIALI: 1\n");
fprintf(pFile, "    FUKANG: 2\n");
fprintf(pFile, "    SANGTANA: 3\n");
fprintf(pFile, "Examples:\n");
fprintf(pFile, "    car 1 2000\n");
}


/***************************************************************************************
Main (the main function)
***************************************************************************************/
int main(int argc, char * argv[])
{
  /* variable declares*/
  char CarMode[8+8];
  int cMode = UNDEFINED_ID;
  char Kilometres[256+8];
  int Kilo = 0;
  double expense = 0;


  /* make sure there are at least 3 arguments*/
  if (argc < 2)
  {
    DisplayProperUsage(stderr);
    exit(-1);
  }


  memset(CarMode,'\0',8+8);
  strncpy(CarMode, argv[1],8);

  cMode = atoi(&CarMode[0]);
  if (cMode != XIALI_ID && cMode != FUKANG_ID && cMode != SANGTANA_ID)
  {
    DisplayProperUsage(stderr);
    return -1;
  }

  memset(Kilometres,'\0',256+8);
  strncpy(Kilometres, argv[2],256);

  Kilo = atoi(Kilometres);
  if(Kilo<=0) {
    DisplayProperUsage(stderr);
    return -1;
  }

// process
  if (cMode == XIALI_ID)
  {
    if(Kilo<=3) {
      printf("XIALI:\nKilometres:[%d],expense:[7]\n",Kilo);
    }
    else {
      expense = (Kilo-3)*2.1+7;
      printf("XIALI:\nKilometres:[%d],expense:[%f]\n",Kilo,expense);
    }
  }
  else if (cMode == FUKANG_ID)
  {
    if(Kilo<=3) {
      printf("FUKANG:\nKilometres:[%d],expense:[8]\n",Kilo);
    } 
    else {
      expense = (Kilo-3)*2.4+8;
      printf("FUKANG:\nKilometres:[%d],expense:[%f]\n",Kilo,expense);
    }
  }
  else if (cMode == SANGTANA_ID)
  {
    if(Kilo<=3) {
      printf("SANGTANA:\nKilometres:[%d],expense:[9]\n",Kilo);
    } 
    else {
      expense = (Kilo-3)*2.7+9;
      printf("SANGTANA:\nKilometres:[%d],expense:[%f]\n",Kilo,expense);
    }
  }



  return 0;
}
storysnail - 2006-12-15 13:47:00
没有排版格式,晕!
small菜菜 - 2006-12-17 13:21:00
hehe
1
查看完整版本: 会C语言的进来~~~~~~~~~~~~~~~~~~