统计选票
某学校的学生会换届,有A、B、C、D、E、F六名学生竞选学生会主席,参加投票的学生代表现有15名,他们在选票上写A-F字母(大小写都可),表示投了对应候选人一票,请编一程序来统计选票。请帮我写个程序!如果有相关的解释就更好了!!!
谢谢!!!
#include <iostream> using namespace std; int main( ) { char *voters = new char[16]; int *vote = new int[7](); /*char temp;*/ /*cout << "Please input 'A to F' to vote :" << endl;*/ for(int i = 0; i < 16; ++i) { do { cout << "Please input rignt 编号'A-F' "<< endl; cin >>voters[i]; }while(voters[i]< 'A' || voters[i] > 'F'); switch(voters[i]) { case 'A': ++vote[0]; break; case 'B': ++vote[1]; break; case 'C': ++vote[2]; break; case 'D': ++vote[3]; break; case 'E': ++vote[4]; break; case 'F': ++vote[5]; break; } } for(int i =0; i < 6; ++i) cout << "第" << i + 1 << "个选手得票为:" << vote[i] << endl; delete [] vote; delete [] voters; }