注册 登录
编程论坛 C++教室

求助,。新人。。

悠哉游哉楠 发布于 2012-10-18 21:05, 472 次点击
#include <iostream>
int add(int first,int second)
{
    std::cout<<"in add (),received"<<first<<" and"
        <<second<<"\n";
    return (first+second);
}




int main()
{
    using std::cout;
    using std::cin;
    cout<<"i'm in main()!\n";
    int a,b,c;
        cout<<"enter two numbers:3 5 ";

    cin>>a;
    cin>>b;
    cout<<"\ncalling add()\n";
    c=add(a,b);
    cout<<"\nback in main().\n";
    cout<<"c was set to"<<c;
    cout<<"excting...\n\n";
    return 0;
}


怎样最后输出是下面这个样子、
输出:
i'm in main ()
enter two number : 3 5

calling add()
in add(),receviced 3 and 5

back in main() .
c was set to 8
excting...
9 回复
#2
悠哉游哉楠2012-10-18 21:09
在线等待中。。
#3
lchpersonal2012-10-19 11:16
你问的问题不太清楚 ,不知道你想问什么!!如下代码你看行不?
#include <iostream>
#include<Windows.h>
using namespace std;

int add(int first,int second)
{
    cout<<"in add(),receviced "<<FIRST<<" AND "<<SECOND<<ENDL;
    return (first+second);
}

int main()
{
   
    cout<<"i'm in main()!\n";
    int a,b,c;
    cout<<"enter two numbers: ";

    cin>>a>>b;
   
    cout<<"\ncalling add()\n";
   
    c=add(a,b);
    cout<<"\nback in main().\n";
    cout<<"c was set to  "<<C<<ENDL;
    cout<<"excting...\n\n";
    system("pause");
    return 0;
}
#4
liman1232012-10-19 12:19
你是要问函数调用的问题还是要问输出的相关问题?对于这段代码这个输出是正确的。
#5
悠哉游哉楠2012-10-19 20:36
回复 4楼 liman123
我想问的  在最后显示的时候  编程出来后 dos下 显示的 是 下面这个样子、、、
i'm in main ()
enter two number : 3 5

calling add()
in add(),receviced 3 and 5

back in main() .
c was set to 8
excting...
  我按照开始的编码后 ,dos下 出现的 是
i'm in main ()
enter two number : 3 5  只是到这里 就卡住 了 我不知道什么原因、、、
#6
悠哉游哉楠2012-10-19 20:40
回复 3楼 lchpersonal
大哥 把你的代码输入后 显示  
\my documents\visual studio 2005\projects\cc\cc\ss称.cpp(7) : error C2065: “FIRST”: 未声明的标识符
1>d:\my documents\visual studio 2005\projects\cc\cc\ss称.cpp(7) : error C2065: “SECOND”: 未声明的标识符
1>d:\my documents\visual studio 2005\projects\cc\cc\ss称.cpp(24) : error C2065: “C”: 未声明的标识符
#7
悠哉游哉楠2012-10-19 20:51
回复 4楼 liman123
谢谢 我知道  我忘了设置 程序暂停。。。
#8
悠哉游哉楠2012-10-19 20:52
回复 5楼 悠哉游哉楠
谢谢  我知道了。。 没有出现全部内容。。~!是我忘了设置程序暂停
#9
wuchunbing2012-10-19 21:17
卡在那里 是在执行
    cin>>a;
    cin>>b;
等你输入 a和b的值  输入3 5 按回车就出来下面的了 。达到你的目的很简单,就是先赋值再引用就OK了 。、
比如int a,b,c;改成 int a=3,b=5,c; 后面的cin>>a;  cin>>b;删除。 你再试下


#10
快乐出发02202012-10-19 22:24
好吧,我对此很无语的说。。。
1