文号
t21384
阅读
5779
回复
12
收藏
7
C++基本中的基本
2009/12/16
IP:香港
#include <stdio.h>
void main() {
     int x, y;
     printf("input your age: ");
     scanf("%i",&x);
     printf("input your brother's age: ");
     scanf("%i",&y);
     if (x<y)
     {
        printf("your age is %i, your brother's age is %i\n",x,y);
        printf("Your brother is older than you!\n");
     }
     else if (x>y)
     {
        printf("You are older than your brother!\n");
     }
     else
     {
        printf("Both guys have the same age!\n");
     }
     printf("goodbye!\n");
     system("pause");
}
t-600作者
17年1个月前IP:未同步
171148
1楼
下載了一個比Microsoft Visual C++ 2008 Express 易用我程序編輯器........."
引用
评论
17年1个月前IP:未同步
171183
2楼
你兄弟比你大还是小的问题,也用C++。。。
引用
评论
t-600作者
17年1个月前IP:未同步
171197
3楼
................"
這是物件導向的基本........"
不是大小的問題..........."
引用
评论
17年1个月前IP:未同步
171326
4楼
我只会VB。。。哈哈  
#include <stdio.h>是什么意思?
引用
评论
t-600作者
17年1个月前IP:未同步
171338
5楼
#include =宣告
<stdio.h>=標頭檔
引用
评论
17年1个月前IP:未同步
171511
6楼
这种太松散了,
应该考虑在if中只判断状态,
将各个printf语句里的string放在事先定义的数组里,
这样在if语句后面用一个printf就把三种情况都打出来.
引用
评论
17年1个月前IP:未同步
171528
7楼
弱弱的说一句,这个叫做面向过程化的C++,简称C。。。
引用
评论
17年1个月前IP:未同步
171541
8楼
LZ写的其实不是C++......那是纯C代码.....
我改成用C++的版本:

#include <iostream>
using namespace std;

int main()
{
    int x, y;
    cout<<"Input your age: "<<endl;
    cin>>x;
    cout<<"Input your brother's age: "<<endl;
    cin>>y;
    if (x<y)
    {
        cout<<"Your age is "<<x<<", your brother's age is "<<y<<"."<<endl;
        cout<<"Your brother is older than you!"<<endl;
    }
    else if (x>y)
    {
        cout<<"You are older than your brother!"<<endl;
    }
    else
    {
        cout<<"Both guys have the same age!"<<endl;
    }
    cout<<"Goodbye!"<<endl;
    return 0;
}
引用
评论
17年1个月前IP:未同步
171544
9楼
关键问题是逻辑和输入输出没有分开, 如8L那样仅仅是用cin/cout取代printf/scanf, 那还是在用C的思想写C++的代码.
引用
评论
17年1个月前IP:未同步
172110
10楼
用的C啊,我比较[怕记$@%&一类的符号,所以没学.
8L,我的"endl"从来没起过作用 [s:261]
引用
评论
17年1个月前IP:未同步
172126
11楼
endl不起作用?你换个编译器看看,比如Dev-Cpp或者Code::blocks...............
最近本人一直在用C做项目.......虽然也在学C++...但是因为喜好的问题....代码风格比较趋近于C........
引用
评论
17年0个月前IP:未同步
174578
12楼
Visual C++ 2008 Express?
您下了个脑残版的VC
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的