標題:
[作業]電費計算機 (二)
[打印本頁]
作者:
陳品肇
時間:
2019-1-11 13:35
標題:
[作業]電費計算機 (二)
本帖最後由 陳品肇 於 2019-1-12 17:27 編輯
針對月份判斷的部分, 以 switch...case 語法改寫.
[attach]5734[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month;
float 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=1.63*degree;
}else if(degree>120 && degree<=330)
{
money=1.63*120+2.38*(degree-120);
}else if(degree>330 && degree<=500)
{
money=1.63*120+2.38*(330-120)+3.52*(degree-330);
}else if(degree>500 && degree<=700)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
}else if(degree>700 && degree<=1000)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
}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=1.63*degree;
}else if(degree>120 && degree<=330)
{
money=1.63*120+2.1*(degree-120);
}else if(degree>330 && degree<=500)
{
money=1.63*120+2.1*(330-120)+2.89*(degree-330);
}else if(degree>500 && degree<=700)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
}else if(degree>700 && degree<=1000)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
}else
{
cout<<"用電度數輸入錯誤!"<<endl;
system("pause");
goto re;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳柏霖
時間:
2019-1-17 21:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int month ,mony;
float give;
cout<<"***歡迎使電費計算機***"<<endl<<endl;
cout<<"請輸入月份:";
cin>>month;
switch(month)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數:";
cin>>mony;
if(mony>=1 && mony<=120)
{
give=mony*1.63;
}else if(mony>=121 && mony<=330)
{
give=120*1.63+(mony-120)*2.38;
}else if(mony>=331 && mony<=500)
{
give=120*1.63+330*2.38+(mony-330)*3.52;
}else if(mony>=501 && mony<=700)
{
give=120*1.63+330*2.38+500*3.52+(mony-500)*4.8;
}else if(mony>=701 && mony<=1000)
{
give=120*1.63+330*2.38+500*3.52+700*4.8+(mony-700)*5.66;
}else if(mony>=1001)
{
give=120*1.63+330*2.38+500*3.52+700*4.8+1000*5.66+(mony-1000)*6.41;
}else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 10:
case 11:
case 12:
cout<<"用電度數:";
cin>>mony;
if(mony>=1 && mony<=120)
{
give=mony*1.63;
}else if(mony>=121 && mony<=330)
{
give=120*1.63+(mony-120)*2.1;
}else if(mony>=331 && mony<=500)
{
give=120*1.63+330*2.1+(mony-330)*2.89;
}else if(mony>=501 && mony<=700)
{
give=120*1.63+330*2.1+500*2.89+(mony-500)*3.94;
}else if(mony>=701 && mony<=1000)
{
give=120*1.63+330*2.1+500*2.89+700*3.94+(mony-700)*4.6;
}else if(mony>=1001)
{
give=120*1.63+330*2.1+500*2.89+700*3.94+1000*4.6+(mony-1000)*5.03;
}else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
break;
defaul:
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
cout<<"電費為"<<give<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡季庭
時間:
2019-2-2 11:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month;
float money;
cout<<"*** 電費計算機 ***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
if(month>=6 && month<=9)
{
cout<<"用電度數: ";
cin>>degree;
if(degree>0 && degree<=120)
{
money=1.63*degree;
}else if(degree>120 && degree<=330)
{
money=1.63*120+2.38*(degree-120);
}else if(degree>330 && degree<=500)
{
money=1.63*120+2.38*(330-120)+3.52*(degree-330);
}else if(degree>500 && degree<=700)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
}else if(degree>700 && degree<=1000)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
}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=1.63*degree;
}else if(degree>120 && degree<=330)
{
money=1.63*120+2.1*(degree-120);
}else if(degree>330 && degree<=500)
{
money=1.63*120+2.1*(330-120)+2.89*(degree-330);
}else if(degree>500 && degree<=700)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
}else if(degree>700 && degree<=1000)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
}else
{
cout<<"輸入錯誤!"<<endl;
system("pause");
goto re;
}
}else
{
cout<<"輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡依宸
時間:
2019-2-2 11:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month;
float money;
cout<<"*** 電費計算機 ***"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
if(month>=6 && month<=9)
{
cout<<"用電度數: ";
cin>>degree;
if(degree>0 && degree<=120)
{
money=1.63*degree;
}else if(degree>120 && degree<=330)
{
money=1.63*120+2.38*(degree-120);
}else if(degree>330 && degree<=500)
{
money=1.63*120+2.38*(330-120)+3.52*(degree-330);
}else if(degree>500 && degree<=700)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
}else if(degree>700 && degree<=1000)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
}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=1.63*degree;
}else if(degree>120 && degree<=330)
{
money=1.63*120+2.1*(degree-120);
}else if(degree>330 && degree<=500)
{
money=1.63*120+2.1*(330-120)+2.89*(degree-330);
}else if(degree>500 && degree<=700)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
}else if(degree>700 && degree<=1000)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
}else
{
cout<<"輸入錯誤!"<<endl;
system("pause");
goto re;
}
}else
{
cout<<"輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
戴偉宸
時間:
2019-2-13 19:49
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month;
float 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=1.63*degree;
}
else if(degree>120 && degree<=330)
{
money=1.63*120+2.38*(degree-120);
}
else if(degree>330 && degree<=500)
{
money=1.63*120+2.38*(330-120)+3.52*(degree-330);
}
else if(degree>500 && degree<=700)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
}
else if(degree>700 && degree<=1000)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
}
else if(degree>=1001)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
}
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=1.63*degree;
}
else if(degree>120 && degree<=330)
{
money=1.63*120+2.1*(degree-120);
}
else if(degree>330 && degree<=500)
{
money=1.63*120+2.1*(330-120)+2.89*(degree-330);
}
else if(degree>500 && degree<=700)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
}
else if(degree>700 && degree<=1000)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
}else if(degree>=1001)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
}
else
{
cout<<"用電度數輸入錯誤!"<<endl;
system("pause");
goto re;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
戴安利
時間:
2019-2-13 20:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month;
float pay;
cout<<"*****電費計算機*****"<<endl<<endl;
cout<<"請輸入月份: ";
cin>>month;
switch(month)
{
case 6:
case 7:
case 8:
case 9:
cout<<"用電度數: ";
cin>>degree;
if(degree>0 && degree<=120)
{
pay = 1.63*degree;
}
else if(degree>120 && degree<=330)
{
pay = 1.63*120+2.38*(degree-120);
}
else if(degree>330 && degree<=500)
{
pay = 1.63*120+2.38*(330-120)+3.52*(degree-330);
}
else if(degree>500 && degree<=700)
{
pay = 1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
}
else if(degree>700 && degree<=1000)
{
pay = 1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
}
else if(degree>=1001)
{
pay = 1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
}
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)
{
pay = 1.63*degree;
}
else if(degree>120 && degree<=330)
{
pay = 1.63*120+2.1*(degree-120);
}
else if(degree>330 && degree<=500)
{
pay = 1.63*120+2.1*(330-120)+2.89*(degree-330);
}
else if(degree>500 && degree<=700)
{
pay = 1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
}
else if(degree>700 && degree<=1000)
{
pay = 1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
}
else if(degree>=1001)
{
pay = 1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
}
else
{
cout<<"用電度數輸入錯誤!"<<endl;
system("pause");
goto re;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"您要繳交的電費共 "<<pay<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
戴唯陞
時間:
2019-2-13 20:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int degree,month;
float 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=1.63*degree;
} else if(degree>120 && degree<=330)
{
money=1.63*120+2.38*(degree-120);
} else if(degree>330 && degree<=500)
{
money=1.63*120+2.38*(330-120)+3.52*(degree-330);
} else if(degree>500 && degree<=700)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
} else if(degree>700 && degree<=1000)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
} else if(degree>=1001)
{
money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
} 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=1.63*degree;
} else if(degree>120 && degree<=330)
{
money=1.63*120+2.1*(degree-120);
} else if(degree>330 && degree<=500)
{
money=1.63*120+2.1*(330-120)+2.89*(degree-330);
} else if(degree>500 && degree<=700)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
} else if(degree>700 && degree<=1000)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
} else if(degree>=1001)
{
money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
} else
{
cout<<"用電度數輸入錯誤!"<<endl;
system("pause");
goto re;
}
break;
default:
cout<<"月份輸入錯誤!"<<endl;
system("pause");
goto re;
}
cout<<endl<<"要繳交的電費共 "<<money<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2