December 31, 2010

c語言程式 計算水費

題目:
一度要4元
0~40度        160元
40~100度     前40度以一樣的價錢計算,後面以一度1.2倍的價錢計算
100~200度   前40度以一樣的價錢計算,後面以一度1.5倍的價錢計算
200~300度   前40度以一樣的價錢計算,後面以一度1.8倍的價錢計算
300度以上    前40度以一樣的價錢計算,後面以一度3倍的價錢計算 

  

#include <stdio.h>
#include <stdlib.h>

int main(void)

{
     float a,f;
     
     printf("請輸入度數:");
     scanf("%f",&a);
     
     if((0<=a) && (a<=40))  f=160;
     
     if((40<a) && (a<100))  f=160+4*1.2*(a-40);
     
     if((100<=a) && (a<200))  f=160+4*1.5*(a-40);
     
     if((200<=a) && (a<300))  f=160+4*1.8*(a-40);
     
     if(300<=a)  f=160+4*3*(a-40);
     
     
     
     printf("所花費的費用是:%f\n",f);   
     
     system("pause");
     return 0 ;
}

0推薦此文章
Today's Visitors: 0 Total Visitors: 16
Personal Category: c語言程式 Topic: learning / education / linguistic
Previous in This Category: c語言程式 溫度等級   Next in This Category: c語言程式 加法(迴圈的計算)
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0