標題:
電費計算機
[打印本頁]
作者:
tonyh
時間:
2013-11-30 15:24
標題:
電費計算機
本帖最後由 tonyh 於 2013-12-7 15:21 編輯
參考台灣電力公司所公怖的
電費計算表格
, 設計一個計算電費的小工具,
讓使用者輸入月份, 與該月份的用電度數, 電腦回應該月份的電費.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d,cost;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
re1:
cout<<"請輸入月份: ";
cin>>m;
re2:
switch(m)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+3.02*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+3.02*(330-120)+4.39*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(d-500);
else if(d>700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 5:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+2.68*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+2.68*(330-120)+3.61*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(d-500);
else if(d>700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto re1;
}
cout<<endl<<"您要繳交的電費共: "<<cost<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃崇維
時間:
2013-11-30 16:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main ()
{
int month;
int electricity, money=0;
cout<<"☆★☆歡迎您使用電費測量器☆★☆"<<endl;
cout<<"請您輸入月份(1~12月): ";
cin>>month;
cout<<"請輸入您這月用電量(度):"<<endl;
cin>>electricity;
system("pause");
return 0;
}
複製代碼
作者:
鎧言
時間:
2013-11-30 16:55
本帖最後由 鎧言 於 2013-12-7 15:34 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d,cost;
cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
re1:
cout<<"請輸入月份: ";
cin>>m;
re2:
switch(m)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+3.02*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+3.02*(330-120)+4.39*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(d-500);
else if(d>700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 5:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+2.68*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+2.68*(330-120)+3.61*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(d-500);
else if(d>700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto re1;
}
cout<<endl<<"您要繳交的電費共: "<<cost<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉泳鱔
時間:
2013-12-7 15:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d,cost;
cout<<"歡迎使用超級電費計算器"<<endl<<endl;
re1:
cout<<"請輸入月份: ";
cin>>m;
re2:
switch(m)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+3.02*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+3.02*(330-120)+4.39*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(d-500);
else if(d>700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 5:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+2.68*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+2.68*(330-120)+3.61*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(d-500);
else if(d>700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto re1;
}
cout<<endl<<"您需要交的電費是: "<<cost<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鎧言
時間:
2013-12-7 15:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d,cost;
cout<<"***歡迎使用電費計算機***"<<endl<<endl;
re1:
cout<<"請輸入月份: ";
cin>>m;
re2:
switch(m)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+3.02*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+3.02*(330-120)+4.39*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(d-500);
else if(d>700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 5:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+2.68*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+2.68*(330-120)+3.61*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(d-500);
else if(d>700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto re1;
}
cout<<endl<<"您要繳交的電費共: "<<cost<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張瀚仁
時間:
2013-12-7 15:49
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m, cost, d;
cout<<"電費計算器"<<endl;
cout<<"請輸入月份:"<<endl;
cin>>m;
switch(m)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數:";
cin>>d;
if(d>=1 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+3.02*(d-330);
else if(d>=331 && d<=500)
cost=2.1*120+3.02*(330-120)+4.39*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(d-500);
else if(d>=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(d-700);
else
cout<<"輸入電量錯誤!!"<<endl;
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 5:
cout<<"用電度數:";
cin>>d;
if(d<=1 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+2.68*(d-330);
else if(d>=331 && d<=500)
cost=2.1*120+2.68*(330-120)+3.61*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(d-500);
else if(d>=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(d-700);
else
cout<<"輸入電量錯誤!!"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
cout<<"您要繳交電費共"<<cost<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭凡瑛
時間:
2013-12-14 18:31
本帖最後由 郭凡瑛 於 2013-12-14 18:37 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m,d,cost;
cout<<"!!!歡迎使用電費計算機!!"<<endl<<endl;
re1:
cout<<"請輸入月份: ";
cin>>m;
re2:
switch(m)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+3.02*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+3.02*(330-120)+4.39*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(d-500);
else if(d>700)
cost=2.1*120+3.02*(330-120)+4.39*(500-330)+4.97*(700-500)+5.63*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 5:
cout<<"用電度數: ";
cin>>d;
if(d>0 && d<=120)
cost=2.1*d;
else if(d>=121 && d<=330)
cost=2.1*120+2.68*(d-120);
else if(d>=331 && d<=500)
cost=2.1*120+2.68*(330-120)+3.61*(d-330);
else if(d>=501 && d<=700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(d-500);
else if(d>700)
cost=2.1*120+2.68*(330-120)+3.61*(500-330)+4.01*(700-500)+4.5*(d-700);
else
{
cout<<"用電度數輸入錯誤!"<<endl;
goto re2;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
goto re1;
}
cout<<endl<<"你要交的電費共: "<<cost<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2