程序清单2.5 ourfunc.cpp

// ourfunc.cpp -- defining your own function

#include <iostream>

void simon(int); // function prototype for simon()

int main()
{
    using namespace std;

    simon(3);
    cout << "Pick an integer: ";
    int count;
    cin >> count;
    simon(count);
    cout << "Done!!" << endl;

    return 0;
}

void simon(int n)
{
    using namespace std;
    cout << "Simon says touch your toes " << n << " times." << endl;
    // void function don't need return statements
}

输出:

Simon says touch your toes 3 times.
Pick an integer: 12
Simon says touch your toes 12 times.
Done!!

猜你喜欢

转载自blog.csdn.net/m0_38101326/article/details/88044252
2.5
cpp