標題:
電費計算機 (一)
[打印本頁]
作者:
鄭繼威
時間:
2023-1-18 19:22
標題:
電費計算機 (一)
本帖最後由 鄭繼威 於 2023-1-18 21:13 編輯
參考台灣電力公司所公怖的
電費計算表格
,設計一個計算電費的小工具,
讓使用者輸入月份,與該月份的用電度數,電腦回應該月份的電費。
單位: 元 / 每度
電費是用
累進式
的
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d;
float p; //加總
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>m;
cout<<"用電度數: ";
cin>>d;
//判斷是不是夏季
if((m>=10 && m<=12) || (m>=1 && m<=5))
{
//非夏季
if(d>1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
else if(d>=701 && d<=1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
else if(d>=501 && d<=700)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
else if(d>=331 && d<=500)
p=120*2.1+(330-120)*2.68+(d-330)*3.61;
else if(d>=121 && d<=330)
p=120*2.1+(d-120)*2.68;
else
//120度以下
p=d*2.1;
}
else
{
//夏季
if(d>1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
else if(d>=701 && d<=1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
else if(d>=501 && d<=700)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
else if(d>=331 && d<=500)
p=120*2.1+(330-120)*3.02+(d-330)*4.39;
else if(d>=121 && d<=330)
p=120*2.1+(d-120)*3.02;
else
p=d*2.1;
}
cout<<endl<<"您要繳交的電費共: "<<p<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
連翊恩
時間:
2023-1-18 21:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d;
float p;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>m;
cout<<"用電度數: ";
cin>>d;
if((m>=10 && m<=12) || (m>=1 && m<=5))
{
if(d>1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
else if(d>700 && d<=1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
else if(d>500 && d<=700)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
else if(d>330 && d<=500)
p=120*2.1+(330-120)*2.68+(d-330)*3.61;
else if(d>120 && d<=330)
p=120*2.1+(d-120)*2.68;
else
p=d*2.1;
}else
{
if(d>1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
else if(d>700 && d<=1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
else if(d>500 && d<=700)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
else if(d>330 && d<=500)
p=120*2.1+(330-120)*3.02+(d-330)*4.39;
else if(d>120 && d<=330)
p=120*2.1+(d-120)*3.02;
else
p=d*2.1;
}
cout<<endl<<"您要繳交的電費共: "<<p<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃裕恩
時間:
2023-1-18 21:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d;
float p;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>m;
cout<<"用電度數: ";
cin>>d;
if((m>=10 && m<=12) || (m>=1 && m<=5))
{
if(d>1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
else if(d>700 && d<=1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
else if(d>500 && d<=700)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
else if(d>330 && d<=500)
p=120*2.1+(330-120)*2.68+(d-330)*3.61;
else if(d>120 && d<=330)
p=120*2.1+(d-120)*2.68;
else
p=d*2.1;
}else
{
if(d>1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
else if(d>700 && d<=1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
else if(d>500 && d<=700)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
else if(d>330 && d<=500)
p=120*2.1+(330-120)*3.02+(d-330)*4.39;
else if(d>120 && d<=330)
p=120*2.1+(d-120)*3.02;
else
p=d*2.1;
}
cout<<endl<<"您要繳交的電費共: "<<p<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李彣
時間:
2023-1-18 21:17
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int m,d;
float p;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
cout<<"請輸入月份:";
cin>>m;
cout<<"用電度數:";
cin>>d;
if((m>=10 && m<=12) || (m>=1 && m<=5))
{
if(d>1000)
{
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
}
else if(d>500 && d<=700)
{
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03;
}
else if(d>330 && d<=500)
{
p=120*2.1+(330-120)*2.68+(500-330)*3.61;
}
else if(d>120 && d<=330)
{
p=120*2.1+(330-120)*2.68;
}
else
{
p=d*2.1;
}
}
else
if(d>1000)
{
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
else if(d>700 && d<=1000)
{
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}
else if(d>500 && d<=700)
{
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}
else if(d>330 && d<=500)
p=120*2.1+(330-120)*3.02+(d-330)*4.39;
}
else if(d>120 && d<=330)
{
p=120*2.1+(d-120)*3.02;
}
else
{
p=d*2.1;
}
}
cout<<endl<<"您要繳交的電費共: "<<p<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林劭杰
時間:
2023-1-31 13:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d;
float p;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>m;
cout<<"用電度數: ";
cin>>d;
if((m>=10 && m<=12) || (m>=1 && m<=5))
{
if(d>1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
else if(d>=701 && d<=1000)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
else if(d>=501 && d<=700)
p=120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
else if(d>=331 && d<=500)
p=120*2.1+(330-120)*2.68+(d-330)*3.61;
else if(d>=121 && d<=330)
p=120*2.1+(d-120)*2.68;
else
p=d*2.1;
}
else
{
if(d>1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
else if(d>=701 && d<=1000)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
else if(d>=501 && d<=700)
p=120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
else if(d>=331 && d<=500)
p=120*2.1+(330-120)*3.02+(d-330)*4.39;
else if(d>=121 && d<=330)
p=120*2.1+(d-120)*3.02;
else
p=d*2.1;
}
cout<<endl<<"您要繳交的電費共: "<<p<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2