The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes case for each An election is contested by five condiadates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each
candidates using an array variable count. In case, a number read is outside the range 1 to 5, the ballot should be considered as a spoilt ballot, and program should also count the number of spoilt ballots. (implement without a class) .........................tomorrow i have to submit to get marks i tried but i can't able to do could you plz anyone
Need help please C++. .....An election?
simple c++ or you use visual 2005 and managed c++?
and what is hard about it? if you tried that means that you almost have the program written
Reply:#include%26lt;iostream%26gt;
using namespace std;
int main() {
int can1 = 0;
int can2 = 0;
int can3 = 0;
int can4 = 0;
int can5 = 0;
int oth = 0;
int input = 0;
char again;
do
{
std::cout %26lt;%26lt; "Who would you like to vote for? 1, 2, 3, 4, or 5?/n" ;
std::cin %26gt;%26gt; input;
if (input == 1)
{
can1 + 1;
}
if (input == 2)
{
can2 + 1;
}
if (input == 3)
{
can3 + 1;
}
if (input == 4)
{
can4 + 1;
}
if (input == 5)
{
can5 + 1;
}
else
{
oth + 1;
}
std::cout %26lt;%26lt; "Is there another person that would like to vote?/n";
std::cin %26gt;%26gt; again;
}while (again == y);
system "pause"
return 0
}
Will that work?
Reply:#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using std::string; using std::cin; using std::cout; using std::endl;
int main()
{
int Vote;
string Candidates[] = {"John Jackson", "Jack Johnson", "John Johnson", "Jack Jackson", "Carl Nimrod"};
int results[] = {0, 0, 0, 0, 0, 0};
while(cin %26gt;%26gt; Vote)
{
if(Vote %26gt; 0 %26amp;%26amp; Vote %26lt; 6)
results[Vote-1]++;
else
results[5]++;
}
for(int x = 0; x %26lt; 5; x++)
{
cout %26lt;%26lt; Candidates[x] %26lt;%26lt;"\t" %26lt;%26lt; results[x] %26lt;%26lt; endl;
}
std::cout %26lt;%26lt; "Number of invalid/spoilt ballots: " %26lt;%26lt; results[5];
return 0;
}
something simple like that?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment