fork download
  1. ///I want this program to accept input in a function called "input" then pass it along to other functions.
  2. //Just trying to wrap my head around passing variables
  3.  
  4. //******
  5. //I would also much rather do this with header files to keep the main source as clean as possible
  6. //*******
  7.  
  8.  
  9. #include <iostream>
  10.  
  11.  
  12. using namespace std;
  13.  
  14. int input()
  15. {
  16. int x, y;
  17. cout << "Enter X: ";
  18. cin >> x;
  19. cout << "Enter Y: ";
  20. cin >> y;
  21. //NOT SURE WHAT IF ANYTHING TO RETURN
  22. }
  23.  
  24.  
  25. int add()
  26. {
  27. cout << "X + Y =" << x + y << endl;
  28. }
  29.  
  30. void main ()
  31. {
  32. input();
  33. add();
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int input()’:
prog.cpp:22:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
prog.cpp: In function ‘int add()’:
prog.cpp:27:26: error: ‘x’ was not declared in this scope
     cout << "X + Y =" << x + y << endl;
                          ^
prog.cpp:27:30: error: ‘y’ was not declared in this scope
     cout << "X + Y =" << x + y << endl;
                              ^
prog.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
prog.cpp: At global scope:
prog.cpp:30:12: error: ‘::main’ must return ‘int’
 void main ()
            ^
stdout
Standard output is empty