C++学习笔记

来源:互联网 发布:linux制作iso镜像 编辑:程序博客网 时间:2024/05/29 16:30

2016年12月27日

2.4.3 用户定义函数

// ourfun.cpp -- define your own function#include<iostream>void simon(int);    // function protype for simon()int main(){    using namespace std;    simon(4);   // call the simon() funciton    cout<< "Pick an interger:";    int count;    cin>> count;    simon(count);   // call it again    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 stament
// convert.cpp --- converts stone to pounds#include<iostream>int stonetolb(int); // function prototypeint main(){    using namespace std;    int stone;    cout<<"Enter the weight in stone.";    cin>>stone;    int pounds = stonetolb(stone);    cout<<stone<<"stone=";    cout<<pounds<<"pounds."<<endl;    return 0;}int stonetolb(int sts){    return 14*sts;}
0 0
原创粉丝点击