Hello. I previously had a question regarding my program and am now stuck again in another section of it.
edit :D
So I need to get the name of the highest voter. I can get the highest votes, but how can I transfer that to display the string (name) rather than the int (votes)?
I'd like an explanation on how it works rather than the answer :/ Been working on this problem all day and I just can't get my head around it.
I was thinking maybe int winner would have to be a string, but I tried it and I received syntax errors. Thanks.
If numOfVotes[pos] contains the highest number of votes, then candidatesLastName[pos] contains the name of the candidate with the highest number of votes.
I'm sorry JLBorges but I just can't figure it out =/ Been reading both your statement and the code over and over and over and I just can't get it... *sigh*
for (loopControl = 0; loopControl < ARRAY_SIZE; loopControl++)
{
if (numOfVotes[loopControl] > highestVote)
highestVote = numOfVotes[loopControl];
winner = //need help here
}//end for loop
Already finds the highest number of votes. candidatesLastName[0] received numOfVotes[0] number of votes, which is percantageOfVotes[0] percent of votes.
By that same logic, if numOfVotes[loopControl] is the highest number of votes, the winner should be candidatesLastName[LoopControl]
Yeah I understand Sylvester would win in that situation, but my problem is I guess the syntax?
So let us use that example where Sylvester is the winner. How do I pass candidatesLastName[2] so that on line 58 it outputs the name?
After this section executes:
1 2 3 4 5 6
//find largest number in array
for (loopControl = 0; loopControl < ARRAY_SIZE; loopControl++){
if (numOfVotes[loopControl] > highestVote)
highestVote = numOfVotes[loopControl];
}
How do I pass that Sylvester won onto line 58 where I am supposed to output the name of candidate and not the number of votes?
I declared winner as int, but that would output a number rather than a string. So I changed that to a string so that winner takes the value of candidatesLastName[2] , or Sylvester. But that is where I am stuck.
Thanks a lot for helping me understand better and lifting some stress off me.
Oh my.. dude you are FREAKING AWESOME!! It all makes sense now that I have seen your example. Line 19 was the one I couldn't think of! Damn dude THANK YOU SO MUCH! :'D
Kind of bummed out I couldn't figure it out though.. I was getting super frustrated cause I had been trying since the morning. Regardless, thank you so much man I can't say it enough. :D
I had never seen that website before. Neat page.
What book would you recommend me for C++ JLBorges? I want to IMPROVE!! I currently have one only and I'd like to get my hands on more.