cant understand the output

i want to know why the output is different
thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>


int any() {
		int opp;
		std::cout << "enter a digit:";
		std::cin >> opp;
		std::cout << opp * 2;
		return 0;
	}
	


int main() {
	std::cout<<any();
		return 0;
}
Last edited on
Line 9 returns a value of zero from your function, explicitly ignoring anything user input in your function. Instead of returning 0 , return the value you wish to pass back to main().

BTW, “any” is a name that will conflict with the Standard Library.

Hope this helps.
Last edited on
but if i just use any() instead of std::cout <<any() it work why is that???what is the rule here...
You need to go review your notes on how functions work.
> i want to know why the output is different
You didn't post anything to compare against (different to what?), and you didn't describe what you thought would happen.

OP wants main() to print the same output as the function
Topic archived. No new replies allowed.