When you have a function and need to scan for 2 different numbers, should the scanf be in the function or in the main() and why?
COKEDUDE 27 Junior Poster in Training
Recommended Answers
Jump to Postit depends on what you're trying to do:
when declaring variables in the
main()
procedure, is because you intend to use them throughout the whole program, though you can't use them in a function (unless you pass them as parameters by reference, not by value); when you declare them …
Jump to PostWhen you have a function and need to scan for 2 different numbers, should the scanf be in the function or in the main() and why?
No, you should not put the input in the function. The function's purpose is to do calculations, so keep it simple. Maybe another function …
All 6 Replies
ndeniche 402 Posting Virtuoso Featured Poster
COKEDUDE 27 Junior Poster in Training
abhimanipal 91 Master Poster
ndeniche 402 Posting Virtuoso Featured Poster
jephthah 1,888 Posting Maven
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.