天少 发表于 2013-7-26 14:31:03

纪念大一的日子,一个简单的C++

//Author:xtyang
//记得大一学C语言,永远都不明白如何调用一个函数,真是好可爱呀。
#include<iostream>
using namespace std;

//定义函数原型
int add(int m,int n);
int minus(int m,int n);

//Main,程序入口
int main()
{
    int r,p,res,opt;
    cout<<"Please input the opt to run responding command.\n"
      <<"1.Add Function.\n"
      <<"2.Minus Function"
      <<endl;
    cin>>opt;
    cout<<"Please input the two num to be calc."<<endl;
    cin>>r>>p;
    switch(opt)
    {
      case 1:
            res = add(r,p);
            break;
      case 2:
            res = minus(r,p);
            break;
      default:
            res = 0;
            break;
    }
    cout<<"The result is:"<<res<<endl;

}
int add(int m,int n)
{
    int res = m+n;
    return (res);
}
int minus(int m,int n)
{
    return (m-n);
}


loong 发表于 2013-7-26 16:55:11

不错 我也在学习c++ 有空多交流

令狐神逸 发表于 2013-8-6 12:44:27

楼主,是你让偶幼小的心灵再次深深的领悟了何谓造旨之高深、文笔之挥洒。。谢谢you!
页: [1]
查看完整版本: 纪念大一的日子,一个简单的C++