一维数组选举

Iria ·
更新时间:2024-11-01
· 910 次阅读

用一维数组相关知识进行选举

#include #include #include using namespace std; void input(string str[], int votes[], int* total, int* max) { *total = 0; *max = 0; cout << "Please Enter the Five Candidates' Last name" << endl; for (int i = 0; i > str[i] >> votes[i]; if (i != 0 && votes[*max] < votes[i]) *max = i; *total += votes[i]; } } void output(string str[], int votes[], int* total, int* max) { cout << "Candidate Votes Received % of Total Votes " << endl; for (int i = 0; i < 5; ++i) { cout << str[i] << " " << votes[i] << " " << setiosflags(ios::fixed) << setprecision(2) << 100 * votes[i] * 1.0 / (*total) << endl; } cout << "Total " << *total << endl << endl; cout << "The Winner of the Election is " << str[*max] << "." << endl; } int main() { //返回0 string lastName[5]; int votes[5]; double per[5]; int total; int max; input(lastName, votes, &total, &max); output(lastName, votes, &total, &max); return 0; }
作者:处女座绛翎儿



维数 一维数组 数组

需要 登录 后方可回复, 如果你还没有账号请 注册新账号