- #include <iostream>
- using namespace std;
- int main()
- {
- float a=0,b=0,c=0,d=0;
- int vote;
- int password,tryagain;
- start:
- cout<<"***歡迎使用秘密投票系統----黑盜選舉***"<<endl;
- cout<<"本次選舉共有三位候選人 1壞誕 2可物 3好漢"<<endl;
- cout<<"請輸入號碼 以投下您可恨的一票";
- cin>>vote;
- if(vote==1)
- {
-
- a++;
- }else if(vote==2)
- {
- b++;
- }else if(vote==3)
- {
- c++;
- }else
- {
- d++;
- }
- system("cls");
- cout<<"您已投票完成! 請等候管理人員的安排"<<endl;
- password:
- cout<<"管理人員在此輸入密碼:";
- cin>>password;
- if(password==32198249)
- {
- cout<<"1.繼續投票 2.公佈投票"<<endl;
- cin>>tryagain;
- if(tryagain==1)
- {
- system("cls");
- goto start;
-
- }else
- {
- system("cls");
- goto result;
- }
-
- }else
- {
- cout<<"輸入錯誤,請重新輸入"<<endl;
- goto password;
- }
- result:
- cout<<"1壞誕"<<a<<"票,2可物"<<b<<"票, 3好漢"<<c<<"票,廢票"<<d<<"票";
-
- cout<<"共有"<< a+b+c+d<<"人投票";
- cout<<"三位候選人的得票率分別為...."<<endl;
- cout<<"1壞誕"<<a/(a+b+c+d)*100<<"%,2可物"<<b/(a+b+c+d)*100<<"%, 3好漢"<<c/(a+b+c+d)*100<<"%,廢票"<<d/(a+b+c+d)*100<<"%";
-
- system("pause");
- return 0;
- }
複製代碼 |