標題:
[作業] 電費計算機
[打印本頁]
作者:
tonyh
時間:
2014-5-3 17:36
標題:
[作業] 電費計算機
本帖最後由 tonyh 於 2014-5-10 16:54 編輯
參考台灣電力公司所公怖的
電費計算表格
, 設計一個計算電費的小工具,
讓使用者輸入月份, 與該月份的用電度數, 電腦回應該月份的電費.
[attach]886[/attach]
[attach]887[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month,money;
cout<<"*** 電費計算機 ***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
if(month>=6 && month<=9)
{
cout<<"用電度數: ";
cin>>degree;
if(degree>0 && degree<=120)
{
money=2.1*degree;
}else if(degree>120 && degree<=330)
{
money=2.1*120+3.02*(degree-120);
}else if(degree>330 && degree<=500)
{
money=2.1*120+3.02*(330-120)+4.39*(degree-330);
}else if(degree>500 && degree<=700)
{
money=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(degree-500);
}else if(degree>700)
{
money=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(degree-700);
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
system("pause");
goto re;
}
}else if((month>=10 && month<=12)||(month>=1 && month<=5))
{
cout<<"用電度數: ";
cin>>degree;
if(degree>0 && degree<=120)
{
money=2.1*degree;
}else if(degree>120 && degree<=330)
{
money=2.1*120+2.68*(degree-120);
}else if(degree>330 && degree<=500)
{
money=2.1*120+2.68*(330-120)+3.61*(degree-330);
}else if(degree>500 && degree<=700)
{
money=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(degree-500);
}else if(degree>700)
{
money=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(degree-700);
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
system("pause");
goto re;
}
}else
{
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張彥承
時間:
2014-5-3 18:07
本帖最後由 張彥承 於 2014-5-10 17:08 編輯
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
re:
int month,a,b;
system("cls");
cout<<"***天才電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
if(month>=6 && month<=9)
{
cout<<"用電度數: ";
cin>>a;
if(a>0 && a<=120)
b=2.1*a;
else if(a>=121 && a<=330)
b=2.1*120+3.02*(a-120);
else if(a>=331 && a<=500)
b=2.1*120+3.02*210+4.39*(a-330);
else if(a>=501 && a<=700)
b=2.1*120+3.02*210+4.39*170+4.97*(a-500);
else if(a>700)
b=2.1*120+3.02*210+4.39*170+4.97*200+5.63*(a-700);
else
{
cout<<"用電度數輸入錯誤"<<endl;
system("pause");
goto re;
}
}
else if((month>=10 && month<=12) || (month>=1 && month<=5))
{
cout<<"用電度數: ";
cin>>a;
if(a>0 && a<=120)
b=2.1*a;
else if(a>=121 && a<=330)
b=2.1*120+2.68*(a-120);
else if(a>=331 && a<=500)
b=2.1*120+2.68*210+3.61*(a-330);
else if(a>=501 && a<=700)
b=2.1*120+2.68*210+3.61*170+4.01*(a-500);
else if(a>700)
b=2.1*120+2.68*210+3.61*170+4.01*200+4.5*(a-700);
else
{
cout<<"用電度數輸入錯誤"<<endl;
system("pause");
goto re;
}
}
else
{
cout<<"月份輸入錯誤"<<endl;
system("pause");
goto re;
}
cout<<"你要繳交的電費共: "<<b<<"元!"<<endl;
system("pause");
return 0;
}
作者:
周雍程
時間:
2014-5-3 18:07
本帖最後由 周雍程 於 2014-5-10 17:06 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c, d;
cout<<"***愛地球電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>a;
if(a>=6 && a<=9)
{
cout<<"用電度數: ";
cin>>b;
if(b>=0<=120)
{
d=b*2.1;
}
if(b>=121 && b<=330)
{
d=120*2.1+(b-120)*3.02;
}
if(b>=331 && b<=500)
{
d=120*2.1+210*3.02+(b-330)*4.39;
}
if(b>=501 && b<=700)
{
d=120*2.1+210*3.02+170*4.39+(b-500)*4.97;
}
if(b>700)
{
d=120*2.1+210*3.02+170*4.39+200*4.97+(b-700)*5.63;
}
cout<<"您要繳交的電費共: "<<d<<"元"<<endl;
}
else if((a>=10 && a<=12) || (a>=1 && a<=5))
{
cout<<"用電度數: ";
cin>>b;
if(b<=120)
{
c=b*2.1;
}
if(b>=121 && b<=330)
{
c=120*2.1+(b-120)*2.68;
}
if(b>=331 && b<=500)
{
c=120*2.1+210*2.68+(b-330)*3.61;
}
if(b>=501 && b<=700)
{
c=120*2.1+210*2.68+170*3.61+(b-500)*4.01;
}
if(b>700)
{
c=120*2.1+210*2.68+170*3.61+200*4.01+(b-700)*4.5;
}
cout<<"您要繳交的電費共: "<<c<<"元"<<endl;
}
else
{
cout<<"輸入錯誤";
}
system("pause");
return 0;
}
複製代碼
作者:
張郁庭
時間:
2014-5-3 18:08
本帖最後由 張郁庭 於 2014-5-10 17:03 編輯
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int eletricity, money, month;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
re:
cout<<"請輸入月份: ";
cin>>month;
if(month>=6 && month<=9)
{
cout<<"用電度數: ";
cin>>eletricity;
if(eletricity>0 && eletricity<=120)
money=2.1*eletricity;
else if(eletricity>=121 && eletricity<=330)
money=2.1*120+3.02*(eletricity-120);
else if(eletricity>=331 && eletricity<=500)
money=2.1*120+3.02*210+4.39*(eletricity-330);
else if(eletricity>=501 && eletricity<=700)
money=2.1*120+3.02*210+4.39*170+4.97*(eletricity-500);
else if(eletricity>700)
money=2.1*120+3.02*210+4.39*170+4.97*200+5.63*(eletricity-700);
else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
}
else if((month>=10 && month<=12) || (month>=1 && month<=5))
{
cout<<"用電度數: ";
cin>>eletricity;
if(eletricity>0 && eletricity<=120)
money=2.1*eletricity;
else if(eletricity>=121 && eletricity<=330)
money=2.1*120+2.68*(eletricity-120);
else if(eletricity>=331 && eletricity<=500)
money=2.1*120+2.68*210+3.61*(eletricity-330);
else if(eletricity>=501 && eletricity<=700)
money=2.1*120+2.68*210+3.61*170+4.01*(eletricity-500);
else if(eletricity>700)
money=2.1*120+2.68*210+3.61*170+4.01*200+4.5*(eletricity-700);
else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
}
else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
cout<<"你要繳交的電費共: "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張峻瑋
時間:
2014-5-5 21:50
本帖最後由 張峻瑋 於 2014-5-10 16:56 編輯
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
re:
int month,a,b;
system("cls");
cout<<"***天才電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
if(month>=6 && month<=9)
{
cout<<"用電度數: ";
cin>>a;
if(a>0 && a<=120)
b=2.1*a;
else if(a>=121 && a<=330)
b=2.1*120+3.02*(a-120);
else if(a>=331 && a<=500)
b=2.1*120+3.02*210+4.39*(a-330);
else if(a>=501 && a<=700)
b=2.1*120+3.02*210+4.39*170+4.97*(a-500);
else if(a>700)
b=2.1*120+3.02*210+4.39*170+4.97*200+5.63*(a-700);
else
{
cout<<"用電度數輸入錯誤"<<endl;
system("pause");
goto re;
}
}
else if((month>=10 && month<=12) || (month>=1 && month<=5))
{
cout<<"用電度數: ";
cin>>a;
if(a>0 && a<=120)
b=2.1*a;
else if(a>=121 && a<=330)
b=2.1*120+2.68*(a-120);
else if(a>=331 && a<=500)
b=2.1*120+2.68*210+3.61*(a-330);
else if(a>=501 && a<=700)
b=2.1*120+2.68*210+3.61*170+4.01*(a-500);
else if(a>700)
b=2.1*120+2.68*210+3.61*170+4.01*200+4.5*(a-700);
else
{
cout<<"用電度數輸入錯誤"<<endl;
system("pause");
goto re;
}
}
else
{
cout<<"月份輸入錯誤"<<endl;
system("pause");
goto re;
}
cout<<"你要繳交的電費共: "<<b<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉得旗
時間:
2014-5-10 15:53
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m, b, c, d;
cout<<"@@@@電費計算機####"<<endl<<endl;
cout<<"輸入月份: ";
cin>>m;
if(m>=6 && m<=9)
{
cout<<"用電度數: ";
cin>>b;
if(b<=120)
{
d=b*2.1;
}
if(b>=121 && b<=330)
{
d=120*2.1+(b-120)*3.02;
}
if(b>=331 && b<=500)
{
d=120*2.1+210*3.02+(b-330)*4.39;
}
if(b>=501 && b<=700)
{
d=120*2.1+210*3.02+170*4.39+(b-500)*4.97;
}
if(b>700)
{
d=120*2.1+210*3.02+170*4.39+200*4.97+(b-700)*5.63;
}
cout<<"您的電費總共: "<<d<<"元"<<endl;
}
else if((m>=10 && m<=12) || (m>=1 && m<=5))
{
cout<<"用電度數: ";
cin>>b;
if(b<=120)
{
c=b*2.1;
}
if(b>=121 && b<=330)
{
c=120*2.1+(b-120)*2.68;
}
if(b>=331 && b<=500)
{
c=120*2.1+210*2.68+(b-330)*3.61;
}
if(b>=501 && b<=700)
{
c=120*2.1+210*2.68+170*3.61+(b-500)*4.01;
}
if(b>700)
{
c=120*2.1+210*2.68+170*3.61+200*4.01+(b-700)*4.5;
}
cout<<"您的電費共: "<<c<<"元"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2