Advertisement
sst311212

三人選舉

Apr 12th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a=0, b=0, c=0, people=0, choose;
  8.     do
  9.     {
  10.         printf("Enter choose (a=1, b=2,c=3,-1 to end): ");
  11.         scanf("%d", &choose);
  12.         switch(choose)
  13.         {
  14.         case 1:
  15.             a++; people++; break;
  16.         case 2:
  17.             b++; people++; break;
  18.         case 3:
  19.             c++; people++; break;
  20.         case -1:
  21.             break;
  22.         default:
  23.             printf("Please enter a valid number.\n");
  24.         }
  25.     } while (choose != -1);
  26.     printf("a\tb\tc\tpeople\n%d\t%d\t%d\t%d\n", a, b, c, people);
  27.     if (a>b && a>c)
  28.         printf("The city leader is a\n");
  29.     else if (b>a && b>c)
  30.         printf("The city leader is b\n");
  31.     else if (c>a && c>b)
  32.         printf("The city leader is c\n");
  33.     else
  34.         printf("This city has no leader.\n");
  35.     system("pause");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement