返回列表 發帖
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.   float a=0,b=0,c=0,d=0;  
  6.   int  vote;
  7.   int password,tryagain;
  8.   start:  
  9.   cout<<"***歡迎使用秘密投票系統----黑盜選舉***"<<endl;
  10.   cout<<"本次選舉共有三位候選人 1壞誕 2可物 3好漢"<<endl;
  11.   cout<<"請輸入號碼 以投下您可恨的一票";  
  12.   cin>>vote;  
  13.   if(vote==1)
  14.   {
  15.       
  16.    a++;   
  17.   }else if(vote==2)
  18. {
  19.    b++;     
  20. }else if(vote==3)
  21. {
  22.    c++;   
  23. }else
  24. {
  25.    d++;     
  26. }      
  27. system("cls");
  28. cout<<"您已投票完成! 請等候管理人員的安排"<<endl;
  29. password:
  30. cout<<"管理人員在此輸入密碼:";  
  31. cin>>password;
  32.   if(password==32198249)
  33.   {
  34.        cout<<"1.繼續投票 2.公佈投票"<<endl;
  35.        cin>>tryagain;
  36.       if(tryagain==1)
  37.       {
  38.        system("cls");               
  39.        goto start;  
  40.       
  41.      }else
  42.      {
  43.        system("cls");     
  44.        goto result;
  45.      }   
  46.      
  47.   }else  
  48. {
  49.     cout<<"輸入錯誤,請重新輸入"<<endl;
  50.    goto password;
  51. }
  52.     result:
  53.     cout<<"1壞誕"<<a<<"票,2可物"<<b<<"票, 3好漢"<<c<<"票,廢票"<<d<<"票";
  54.            
  55.     cout<<"共有"<< a+b+c+d<<"人投票";
  56.     cout<<"三位候選人的得票率分別為...."<<endl;
  57.     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<<"%";      
  58.      
  59.   system("pause");   
  60.   return 0;
  61. }
複製代碼

TOP

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.   float a=0,b=0,c=0,d=0;  
  6.   int  vote;
  7.   int password,tryagain;
  8.   start:  
  9.   cout<<"***歡迎使用秘密投票系統----黑盜選舉***"<<endl;
  10.   cout<<"本次選舉共有三位候選人 1壞誕 2可物 3好漢"<<endl;
  11.   cout<<"請輸入號碼 以投下您可恨的一票";  
  12.   cin>>vote;  
  13.   if(vote==1)
  14.   {
  15.       
  16.    a++;   
  17.   }else if(vote==2)
  18. {
  19.    b++;     
  20. }else if(vote==3)
  21. {
  22.    c++;   
  23. }else
  24. {
  25.    d++;     
  26. }      
  27. system("cls");
  28. cout<<"您已投票完成! 請等候管理人員的安排"<<endl;
  29. password:
  30. cout<<"管理人員在此輸入密碼:";  
  31. cin>>password;
  32.   if(password==32198249)
  33.   {
  34.        cout<<"1.繼續投票 2.公佈投票"<<endl;
  35.        cin>>tryagain;
  36.       if(tryagain==1)
  37.       {
  38.        system("cls");               
  39.        goto start;  
  40.       
  41.      }else
  42.      {
  43.        system("cls");     
  44.        goto result;
  45.      }   
  46.      
  47.   }else  
  48. {
  49.     cout<<"輸入錯誤,請重新輸入"<<endl;
  50.    goto password;
  51. }
  52.     result:
  53.     cout<<"1壞誕"<<a<<"票,2可物"<<b<<"票, 3好漢"<<c<<"票,廢票"<<d<<"票";
  54.            
  55.     cout<<"共有"<< a+b+c+d<<"人投票";
  56.     cout<<"三位候選人的得票率分別為...."<<endl;
  57.     cout<<"1壞誕"<<a/(a+b+c+d)*100<<"%,2可物"<<b/(a+b+c+d)*100<<"%, 3好漢"<<c/(a+b+c+d)*100<<"%";
  58.     if(a>b && a>c)
  59.     {
  60.      cout<<"恭喜壞誕當選"<<endl;   
  61.     }else  if(b>a && b>c)
  62.     {
  63.      cout<<"恭喜可物當選"<<endl;      
  64.     }else  if(c>a && c>b)
  65.     {
  66.      cout<<"恭喜好漢當選"<<endl;     
  67.     }else
  68.     {
  69.      cout<<"本次投票無效"<<endl;   
  70.     }
  71.   system("pause");   
  72.   return 0;
  73. }
複製代碼

TOP

返回列表