Question 7
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
void percentage(int got, int total) {
return got * 100 / total;
}
int main() {
std::cout << percentage(45, 50) << '\n';
return 0;
}
- A The division must use doubles
- B A void function cannot return a value (and its result cannot be printed); the return type should be int or double Correct
- C got must be const
- D percentage must take references
Correct Answer: Option B
Change it to int percentage(int got, int total) – or double for a fractional result.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!