標題:
電費計算機 (二)
[打印本頁]
作者:
tonyh
時間:
2014-5-10 16:58
標題:
電費計算機 (二)
本帖最後由 tonyh 於 2014-5-10 17:44 編輯
針對月份判斷的部分, 以 switch...case 語法改寫.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month,money;
cout<<"*** 電費計算機 ***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6:
case 7:
case 8:
case 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;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 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;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張峻瑋
時間:
2014-5-10 17:14
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
re:
int month,a,b;
system("cls");
cout<<"***天才電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6:
case 7:
case 8:
case 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;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 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;
}
break;
default:
{
cout<<"月份輸入錯誤"<<endl;
system("pause");
goto re;
}
}
cout<<"你要繳交的電費共: "<<b<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張郁庭
時間:
2014-5-10 17:48
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree, money, month;
cout<<"***小米電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6:
case 7:
case 8:
case 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;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 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;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉得旗
時間:
2014-5-10 17:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int m, b, c, d;
cout<<"@@@@電費計算機####"<<endl<<endl;
cout<<"輸入月份: ";
cin>>m;
switch(m)
{
case 6:
case 7:
case 8:
case 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;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 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;
}
複製代碼
作者:
張彥承
時間:
2014-5-10 17:52
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month,money;
cout<<"*** 電費計算機 ***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6:
case 7:
case 8:
case 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;
}
break;
case 10:
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
case 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;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
周雍程
時間:
2014-5-10 17:54
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b, c, d;
cout<<"***愛地球電費計算機***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>a;
switch(a)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>b;
if(b>=0 && 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;
}
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 10:
case 11:
case 12:
cout<<"用電度數: ";
cin>>b;
if(b>=0 && b<=120)
{
d=b*2.1;
}
if(b>=121 && b<=330)
{
d=120*2.1+(b-120)*2.68;
}
if(b>=331 && b<=500)
{
d=120*2.1+210*2.68+(b-330)*3.61;
}
if(b>=501 && b<=700)
{
d=120*2.1+210*2.68+170*3.61+(b-500)*4.01;
}
if(b>700)
{
d=120*2.1+210*2.68+170*3.61+200*4.01+(b-700)*4.5;
}
cout<<"您要繳交的電費共: "<<d<<"元"<<endl;
break;
default:
cout<<"輸入錯誤";
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2