Change endl to "\n" and work on your indentation instead of optimization.
pseudorandom21
Practically a Posting Shark
890 posts since Jan 2011
Reputation Points: 216
Solved Threads: 111
//Also you shouldn't use "exit" in a C++ program, because it may cause destructors to not be called.
This probably isn't true anymore, but normally it isn't excusable to use exit() anywhere except the main function, instead you might want to throw an exception and then the caller can elect to handle it, or not (terminate the program).
"endl" does more than insert a newline, it also flushes the buffer. If you need to optimize such a trivial program, well.. There must be something unseen happening.
If you just want it to be easier to work with declare constants for array sizes and decompose it into more functions.
pseudorandom21
Practically a Posting Shark
890 posts since Jan 2011
Reputation Points: 216
Solved Threads: 111
What I find strange is the switch/case statement when you have a choice base on a simple number.
if (choice<1 || choice>maxCandidates)
votes[choice-1]++;
else
{
std::cout<<"Incorect number... Exiting"<<std::endl;
/etc...
}
Then the next thing that look strange is calling votes1() from votes1(). Surely
write a function getVotes() and then do the decision and processing outside that
function in another loop/control structure.
Finally, if you define optimization you have to specify what you mean, IO, CPU, size, or what I think you really mean, making the code clear.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138