標題:
電費計算機 (一)
[打印本頁]
作者:
陳品肇
時間:
2022-4-9 10:04
標題:
電費計算機 (一)
本帖最後由 陳品肇 於 2022-4-9 11:42 編輯
參考台灣電力公司所公怖的
電費計算表格
,設計一個計算電費的小工具,
讓使用者輸入月份,與該月份的用電度數,電腦回應該月份的電費。
單位: 元 / 每度
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
// 金額總計
float total=0;
// 非夏月條件 10~12 or 1~5
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
// 非夏月
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
進階補充程式方法二:
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
// 金額總計
float total=0;
// 預設陣列都是 夏月的係數
float arr[]={2.1,3.02,4.39,5.44,6.16,6.71};
// 非夏月條件 10~12 or 1~5
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
// 把預設係數換成非夏月
arr[0]=2.1;
arr[1]=2.68;
arr[2]=3.61;
arr[3]=4.48;
arr[4]=5.03;
arr[5]=5.28;
}
if(d<=120)
{
total = d*arr[0];
}else if(d>=121 && d<=330)
{
total = 120*arr[0] + (d-120)*arr[1];
}else if(d>=331 && d<=500)
{
total = 120*arr[0] + (330-120)*arr[1] + (d-330)*arr[2];
}else if(d>=501 && d<=700)
{
total = 120*arr[0] +(330-120)*arr[1]+(500-330)*arr[2]+(d-500)*arr[3];
}else if(d>=701 && d<=1000)
{
total = 120*arr[0]+(330-120)*arr[1]+(500-330)*arr[2]+(700-500)*arr[3]+(d-700)*arr[4];
}else
{
total =120*arr[0]+(330-120)*arr[1]+(500-330)*arr[2]+(700-500)*arr[3]+(1000-700)*arr[4]+(d-1000)*arr[5];
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾善勤
時間:
2022-4-9 11:14
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鍾易澄
時間:
2022-4-9 11:15
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
// 金額總計
float total=0;
// 非夏月條件 10~12 or 1~5
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
// 非夏月
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林鴻慶
時間:
2022-4-9 11:19
#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;
}
複製代碼
作者:
林紘憲
時間:
2022-4-9 11:19
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
// 金額總計
float total=0;
// 非夏月條件 10~12 or 1~5
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
}else
{
// 夏月
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + 210*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<"總計:"<<total<<endl;
system("pause");
return 0;
}
複製代碼
作者:
高昀昊
時間:
2022-4-9 11:19
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
徐譽豈
時間:
2022-4-9 11:20
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int month,d;
cout<<"***歡迎使用電費計算機***"<<endl;
cout<<endl;
cout<<"請輸入月份:";
cin>>month;
cout<<"用電度數:";
cin>>d;
cout<<endl;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交的電費共:"<<total<<"元!";
system("pause");
return 0;
}
複製代碼
作者:
田家齊
時間:
2022-4-9 11:21
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int month=0,d=0;
float total=0;
cout<<"***歡迎使用小米的電費計機***"<<endl;
cout<<"輸入月份:";
cin>>month;
cout<<"用電度數";
cin>>d;
if((month>=10&&month<=12)||(month>=1&&month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<"總計:"<<total<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許宸瑀
時間:
2022-4-9 11:25
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
柳侑辰
時間:
2022-4-9 11:26
本帖最後由 柳侑辰 於 2022-4-9 11:29 編輯
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
孫子傑
時間:
2022-4-9 11:27
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
int month,d;
cout<<"請輸入月份: ";
cin>>month;
cout<<"用電度數: ";
cin>>d;
// 金額總計
float total=0;
// 非夏月條件 10~12 or 1~5
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
// 非夏月
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
高鋐鈞
時間:
2022-4-9 11:28
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int month,x;
cout<<"***歡迎使用小米的電費計算機***"<<endl;
cout<<"請輸入月份:";
cin>>month;
cout<<"用電度數:";
cin>>x;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(x<=120)
{
total = x*2.1;
}else if(x>=121 && x<=330)
{
total = 120*2.1 + (x-120)*2.68;
}else if(x>=331 && x<=500)
{
total = 120*2.1 + (330-120)*2.68 + (x-330)*3.61;
}else if(x>=501 && x<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(x-500)*4.48;
}else if(x>=701 && x<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(x-700)*5.03;
}
} else{
if(x<=120)
{
total=2.1*x;
}else if(x>=121&&x<=330)
{
total=120*2.1+(x-120)*3.02;
}else if(x>=331 && x<=500)
{
total = 120*2.1 + 210*3.02 + (x-330)*4.39;
}else if(x>=501 && x<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(x-500)*5.44;
}else if(x>=701 && x<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(x-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(x-1000)*6.71;
}
}
cout<<"您要繳交電費共:" <<total<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
潘柏予
時間:
2022-4-9 11:28
提示:
作者被禁止或刪除 內容自動屏蔽
作者:
潘柏升
時間:
2022-4-9 11:29
提示:
作者被禁止或刪除 內容自動屏蔽
作者:
許馹東
時間:
2022-4-9 11:42
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int month,d;
cout<<"***歡迎來到小米的電費計算機***"<<endl;
cout<<endl;
cout<<"請輸入月份:";
cin>>month;
cout<<"用電度數:";
cin>>d;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(d<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*2.68;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
}else
{
total =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<=120)
{
total = d*2.1;
}else if(d>=121 && d<=330)
{
total = 120*2.1 + (d-120)*3.02;
}else if(d>=331 && d<=500)
{
total = 120*2.1 + 210*3.02 + (d-330)*4.39;
}else if(d>=501 && d<=700)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
}else if(d>=701 && d<=1000)
{
total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
}else
{
total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭博鈞
時間:
2022-4-9 12:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int month,o;
cout<<"***歡迎使用電費計算機***"<<endl<<endl;
cout<<"請輸入月份:";
cin>>month;
cout<<"用電度數:";
cin>>o;
float total=0;
if((month>=10 && month<=12)||(month>=1 && month<=5))
{
if(o<=120)
{
total=o*2.1;
}else if(o>=121 && o<=330)
{
total=120*2.1+(o-120)*2.68;
}else if(o>=331 && o<=500)
{
total=120*2.1+210*2.68+(o-330)*3.61;
}else if(o>=501 && o<=700)
{
total=120*2.1+(330-120)*2.68+(500-330)*3.61+(o-500)*4.48;
}else if(o>=701 && o<=1000)
{
total=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(o-700)*5.03;
}else
{
total=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(o-1000)*5.28;
}
}else
{
if(o<=120)
{
total=o*2.1;
}else if(o>=121 && o<=330)
{
total=120*2.1+(o-120)*3.02;
}else if(o>=331 && o<=500)
{
total=120*2.1+210*3.02+(o-330)*4.39;
}else if(o>=501 && o<=700)
{
total=120*2.1+(330-120)*3.02+(500-330)*4.39+(o-500)*5.44;
}else if(o>=701 && o<=1000)
{
total=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(o-700)*6.16;
}else
{
total=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(o-1000)*6.71;
}
}
cout<<endl;
cout<<"您要繳交的電費共:"<<total<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2