高手进来帮忙一下,C++的,其他语言不要

ironyouth 2008-04-09 08:48:39
/*
7. Write a program that allows the user to enter the last names of five candidates
in a local election and the number of votes received by each candidate.
The program should then output each candidate’s name, the number of votes received,
and the percentage of the total votes received by the candidate.

Use a minimum of 2 functions (in addition to main).
At least one of those functions must pass an array and its size as parameters.

Your program should also output the winner of the election. A sample output is:

Candidate Votes Received % of Total Votes
Johnson 5000 25.91
Miller 4000 20.73
Duffy 6000 31.09
Robinson 2500 12.95
Ashtony 1800 9.33
Total 19300


The Winner of the Election is Duffy.

*/

#include <iostream>
#include <string>
using namespace std;

// must have 2 function using void function and pass by reference &

int main ()
{
string lastName1,lastName2,lastName3,lastName4,lastName5; // last names of five candidates.
int votesL1, votesL2,votedL3,votesL4,votesL5,total; // votes received
double percent1vote,percent2Vote,percent3Vote, percent4Vote, percent5Vote; // % of Total votes

cout << "Please Enter the Five Candidates' Last name" << endl;
cin >> lastName1 //怎么样可以一起把5个名字一起输入进去还是要一个一个来?


return 0;
}

void function ( )
{


return 0;
}

void function ( )
{



return 0;
}
...全文
100 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
c_spark 2008-04-09
  • 打赏
  • 举报
回复
输入数据是一个字符串,一个整数,而且规定了变量名,只有一个一个输入
然后统计输出就行,不知道你的两个function要做什么用?
如果是输入,输出,还得将所有参数的引用传过去,太麻烦点啊
程序挺简单就是对votes求和,记录votes最多的获胜
输出以两位小数的百分比(控制精度)
使用cout<<lastName1<<" "<<setiosflags(ios::fixed)<<setprecision(2)<<percent1vote<<endl;
就行啊,具体实现还是你自己写吧...
qmm161 2008-04-09
  • 打赏
  • 举报
回复
cin >> lastName1 //怎么样可以一起把5个名字一起输入进去还是要一个一个来?

cin >> lastName1 >> lastName2 >> lastName3 >> ...
  • 打赏
  • 举报
回复
俺不是高手,误入进来
cx36001390 2008-04-09
  • 打赏
  • 举报
回复
cin >> lastName1 >> lastName2 >> lastName3 >> lastName4 >> lastName5;
mtcat 2008-04-09
  • 打赏
  • 举报
回复
你这样的写法要一个一个来了。
你可以写成数组,用一个循环来做。

string lastName[5];
for(int i = 0; i < 5; ++i)
{
cin >> lastName[i];
}
p0303230 2008-04-09
  • 打赏
  • 举报
回复
一个个来
输一个要清一次缓冲区

64,849

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧