您的位置:首页 > 编程语言 > C语言/C++

C++学习笔记

2017-01-13 08:55 274 查看
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 prototype
int 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: