標題:
[作業] 電費計算機
[打印本頁]
作者:
tonyh
時間:
2012-4-7 17:30
標題:
[作業] 電費計算機
本帖最後由 tonyh 於 2012-4-14 17:43 編輯
參考台灣電力公司所公怖的
電費計算表格
, 設計一個計算電費的小工具,
讓使用者輸入月份, 與該月份的用電度數, 電腦回應該月份的電費.
#include<iostream>
using namespace std;
int main()
{
int month, degree, bill;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
start1:
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6: case 7: case 8: case 9:
start2:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*3.02+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start2;
}
break;
case 1: case 2: case 3: case 4: case 5: case 10: case 11: case 12:
start3:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*2.68+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start3;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto start1;
}
cout<<"您"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉漢文
時間:
2012-4-7 22:14
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
int month;
int electricity, money=0;
cout<<"☆★☆歡迎您使用電費測量器☆★☆"<<endl;
cout<<"請您輸入您這個月的電費(1~12月): ";
cin>>month;
cout<<"請輸入您這月用電量(度):"<<endl;
cin>>electricity;
if(month>=6 && month<10)
{
if(electricity<=110)
{
money=electricity*2.1;
}else if(electricity>=111 && electricity<=330)
{
money=electricity*3.02;
}else if(electricity>=331 && electricity<=500)
{
money=electricity*4.05;
}else if(electricity>=501 && electricity<=700)
{
money=electricity*4.51;
}else if(electricity>700)
{
money=electricity*5.1;
}
}
if(month<=5 && month>=10)
{
if(electricity<=110)
{
money=electricity*2.1;
}else if(electricity>=111 && electricity<=330)
{
money=electricity*2.68;
}else if(electricity>=331 && electricity<=500)
{
money=electricity*3.27;
}else if(electricity>=501 && electricity<=700)
{
money=electricity*3.55;
}else if(electricity>700)
{
money=electricity*3.97;
}
}
cout<<"你這個月的電費是"<<electricity<<"度 ,一共是"<<money<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t3742238
時間:
2012-4-14 11:07
本帖最後由 t3742238 於 2012-4-21 15:59 編輯
#include<iostream>
using namespace std;
int main()
{
float m, kWh, tariff;
cout<<"☆★☆歡迎使用電費計算機★☆★"<<endl;
again:
cout<<"請問現在是幾月:"<<endl;
cin>>m;
if(m>12)
{
cout<<"你是來鬧的歐??"<<endl;
goto again;
}else if(m>=5 && m<=9)
{
goto summer;
}else
{
cout<<"請問電表是多少度:"<<endl;
cin>>kWh;
if(kWh<=110)
{
tariff=2.1*110;
}if(kWh>=111 && kWh<=330)
{
tariff=2.1*110+(kWh-110)*2.68;
}if(kWh>=331 && kWh<=500)
{
tariff=2.1*110+(330-110)*2.68+(kWh-330)*3.27;
}if(kWh>=501 && kWh<=700)
{
tariff=2.1*110+(330-110)*2.68+(700-500)*3.27+(kWh-500)*3.55;
}if(kWh>700)
{
tariff=110*2.1+(330-110)*2.68+(500-330)*3.27+(700-500)*3.55+(kWh-700)*3.97;
}
} cout<<"本月需付:"<<tariff<<"元"<<endl;
summer:
cout<<"請問電表是多少度:"<<endl;
cin>>kWh;
if(kWh<=110)
{
tariff=2.1*110;
}if(kWh>=111 && kWh<=330)
{
tariff=2.1*110+(kWh-110)*3.02;
}if(kWh>=331 && kWh<=500)
{
tariff=2.1*110+(330-110)*3.02+(kWh-330)*4.05;
}if(kWh>=501 && kWh<=700)
{
tariff=2.1*110+(330-110)*3.02+(700-500)*4.05+(kWh-500)*4.51;
}if(kWh>700)
{
tariff=2.1*110+(330-110)*3.02+(500-330)*4.05+(700-500)*4.51+(kWh-700)*5.1;
}
cout<<"本月需付:"<<tariff<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉漢文
時間:
2012-4-14 17:32
本帖最後由 劉漢文 於 2012-4-21 13:15 編輯
#include<iostream>
using namespace std;
int main()
{
int month, degree, bill;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
start1:
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6: case 7: case 8: case 9:
start2:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*3.02+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start2;
}
break;
case 1: case 2: case 3: case 4: case 5: case 10: case 11: case 12:
start3:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*2.68+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start3;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto start1;
}
cout<<"您"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡昀佑
時間:
2012-4-14 17:34
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
float bill;
int month, dregree;
start1:
cout<<"請輸入月份";
cin>>month;
goto start2;
switch (month)
{
case6: case7: case8: case9:
start2:
cout<<"請輸入該月電費度數:";
cin>>dregree;
if(dregree>700)
{
bill=(dregree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(dregree>500 && dregree<=700)
{
bill=(dregree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(dregree>330&& dregree<=500)
{
bill=(dregree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(dregree>110&& dregree<=330)
{
bill=(dregree-110)*3.02+110*2.1;
}else if(dregree>110&& dregree<=330)
{
bill=dregree*2.1;
}else
{
cout<<"輸入錯誤!!";
}
}
system("pause");
return 0;
}
複製代碼
作者:
t2364705
時間:
2012-4-14 20:02
本帖最後由 t2364705 於 2012-4-21 09:57 編輯
#include<iostream>
using namespace std;
int main()
{
int month, degree, bill;
cout<<"***歡迎使用家用電費計算機***"<<endl<<endl;
start1:
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6: case 7: case 8: case 9:
start2:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*3.02+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start2;
}
break;
case 1: case 2: case 3: case 4:
case 5: case 10: case 11: case 12:
start3:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*2.68+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start3;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto start1;
}
cout<<"您"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t2364705
時間:
2012-4-14 20:02
本帖最後由 t2364705 於 2012-4-21 09:55 編輯
#include<iostream>
using namespace std;
int main()
{
int month, degree, bill;
cout<<"***歡迎使用家用電費計算機***"<<endl<<endl;
start1:
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6: case 7: case 8: case 9:
start2:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*3.02+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start2;
}
break;
case 1: case 2: case 3: case 4:
case 5: case 10: case 11: case 12:
start3:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*2.68+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start3;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto start1;
}
cout<<"您"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
尤泓鈞
時間:
2012-4-21 16:01
#include<iostream>
using namespace std;
int main()
{
int month, degree, bill;
cout<<"☆歡迎使用電費計算機☆"<<endl<<endl;
start1:
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6: case 7: case 8: case 9:
start2:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*3.02+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start2;
}
break;
case 1: case 2: case 3: case 4: case 5: case 10: case 11: case 12:
start3:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*2.68+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start3;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto start1;
}
cout<<"你"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡昀佑
時間:
2012-4-21 16:09
#include<iostream>
using namespace std;
int main()
{
int month, degree, bill;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
start1:
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6: case 7: case 8: case 9:
start2:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*3.02+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start2;
}
break;
case 1: case 2: case 3: case 4: case 5: case 10: case 11: case 12:
start3:
cout<<"請輸入該月份的用電度數: ";
cin>>degree;
if(degree>700)
{
bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>500 && degree<=700)
{
bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>330 && degree<=500)
{
bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
}else if(degree>110 && degree<=330)
{
bill=(degree-110)*2.68+110*2.1;
}else if(degree>0 && degree<=110)
{
bill=degree*2.1;
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto start3;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto start1;
}
cout<<"您"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2