1. // Abstraction and scope
2.
3. #include <cs50.h>
4. #include <stdio.h>
5.
6. int get_positive_int(string prompt);
7.
8. int main(void)
9. {
10. int i = get_positive_int("Positive integer: ");
11. printf("%i\n", i);
12. }
13.
14. // Prompt user for positive integer
15. int get_positive_int(string prompt)
16. {
17. int n;
18. do
19. {
20. n = get_int("%s", prompt);
21. }
22. while (n < 1);
23. return n;
24. }
I am having trouble understanding the program positive.c.
Q.1: When the program starts the main function at line 10 calls the "get_positive_int" function, at this point the flow control should move to line 15 and line 11 should not be executed, hence no print message. But the program prints the message.
Q.2 Function "get_positive_int" repeats itself after false value but prints the message why? "get_int" should prompt for the user input but no print the message "Positive integer: ". During this loop why it prints the message as there is no referece to it.