IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 3: [Algorithms] – Linear Search, Binary Search, Bubble Sort, Selection Sort, Recursion, Merge Sort › How to print winner
- This topic is empty.
-
AuthorPosts
-
January 21, 2023 at 9:34 am #1050
In particular,
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
if (candidates[canc].votes > necand/2) { printf("%s", candidates[canc].name); return true; break; }
[/dm_code_snippet]
The error message received while submitting the project is:
print_winner did not print winner of election
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// Check if election has been won bool won = print_winner(); if (won) { break; }
[/dm_code_snippet]
t appears that the above code as part of the main function will remain as it is since there is no mention of TO DO.
My understanding is that the brackets denoting void with print_winner() should give the name of winner candidate as output here if won = true. And that name of winner is coming from print_winner function.
Although from the current code, getting name of winner candidate as output, unable to figure out the reason behind the error message.
Reply
https://edstem.org/us/courses/176/discussion/2419750?comment=5530115[learn_press_profile]
-
AuthorPosts
- You must be logged in to reply to this topic.