1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // ourfunc.cpp -- defining your own function #include <iostream> void simon(int); // function prototype for simon() -- This tells the compiler that there is going to be an integer in the simon function? also why void? int main() { using namespace std; simon(3); // call the simon() function -- Is this line assigning integer 3 to simon for use in int n later? cout << "Pick an integer: "; int count; cin >> count; simon(count); // call it again -- This is assigning whatever input integer user puts in into variable count? cout << "Done!" << endl; cin.get(); cin.get(); return 0; } void simon(int n) // define the simon() function -- void? Explanation? Also why does it say int n now instead of count? { using namespace std; cout << "Simon says touch your toes " << n << " times." << endl; // So int n took the input value from count and used it, how? } // void functions don't need return statements -- Why? |
Ly8gb3VyZnVuYy5jcHAgLS0gZGVmaW5pbmcgeW91ciBvd24gZnVuY3Rpb24KI2luY2x1ZGUgPGlvc3RyZWFtPgp2b2lkIHNpbW9uKGludCk7IC8vIGZ1bmN0aW9uIHByb3RvdHlwZSBmb3Igc2ltb24oKSAtLSBUaGlzIHRlbGxzIHRoZSBjb21waWxlciB0aGF0IHRoZXJlIGlzIGdvaW5nIHRvIGJlIGFuIGludGVnZXIgaW4gdGhlIHNpbW9uIGZ1bmN0aW9uPyBhbHNvIHdoeSB2b2lkPwoKaW50IG1haW4oKQp7CiAgICB1c2luZyBuYW1lc3BhY2Ugc3RkOwogICAgc2ltb24oMyk7ICAgLy8gY2FsbCB0aGUgc2ltb24oKSBmdW5jdGlvbiAtLSBJcyB0aGlzIGxpbmUgYXNzaWduaW5nIGludGVnZXIgMyB0byBzaW1vbiBmb3IgdXNlIGluIGludCBuIGxhdGVyPwogICAgY291dCA8PCAiUGljayBhbiBpbnRlZ2VyOiAiOwogICAgaW50IGNvdW50OwogICAgY2luID4+IGNvdW50OwogICAgc2ltb24oY291bnQpOyAgIC8vIGNhbGwgaXQgYWdhaW4gLS0gVGhpcyBpcyBhc3NpZ25pbmcgd2hhdGV2ZXIgaW5wdXQgaW50ZWdlciB1c2VyIHB1dHMgaW4gaW50byB2YXJpYWJsZSBjb3VudD8KICAgIGNvdXQgPDwgIkRvbmUhIiA8PCBlbmRsOwogICAgY2luLmdldCgpOwogICAgY2luLmdldCgpOwogICAgcmV0dXJuIDA7Cgp9Cgp2b2lkIHNpbW9uKGludCBuKSAgIC8vIGRlZmluZSB0aGUgc2ltb24oKSBmdW5jdGlvbiAtLSB2b2lkPyBFeHBsYW5hdGlvbj8gQWxzbyB3aHkgZG9lcyBpdCBzYXkgaW50IG4gbm93IGluc3RlYWQgb2YgY291bnQ/CnsKICAgIHVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAgICBjb3V0IDw8ICJTaW1vbiBzYXlzIHRvdWNoIHlvdXIgdG9lcyAiIDw8IG4gPDwgIiB0aW1lcy4iIDw8IGVuZGw7IC8vIFNvIGludCBuIHRvb2sgdGhlIGlucHV0IHZhbHVlIGZyb20gY291bnQgYW5kIHVzZWQgaXQsIGhvdz8KfSAgIC8vIHZvaWQgZnVuY3Rpb25zIGRvbid0IG5lZWQgcmV0dXJuIHN0YXRlbWVudHMgLS0gV2h5Pwo=
-
upload with new input
-
result: Success time: 0s memory: 2856 kB returned value: 0
Simon says touch your toes 3 times. Pick an integer: Simon says touch your toes -1216786444 times. Done!


