简单的问题.这段代码那里出错? 谢谢
#include <iostream>
using namespace std;
int main() {
int i;
cout<<"type a number and 'enter'"<<endl;
cin>>i;
if (i>5)
cout<<"it's greater than 5"<<endl;
else
cout<< "It's less than 5"<<endl;
else
cout<< "It's equal to 5 "<<endl;
cout<< "type a number and 'enter'"<<endl;
cin>>i;
if(i<10)
if(i>5)
cout<< "5<i<10"<<endl;
else
cout<< "i<=5"<<endl;
else
cout<< "i>=10"<<endl;
}
问题点数:100、回复次数:5Top
1 楼catface(峰)回复于 2003-09-01 23:00:55 得分 20
IF 连接两个ELSE根本没区别么
比如MAIN下面这段
int i;
cout<<"type a number and 'enter'"<<endl;
cin>>i;
if (i>5)
cout<<"it's greater than 5"<<endl;
else
cout<< "It's less than 5"<<endl;
else
cout<< "It's equal to 5 "<<endl;
如果I小于5 是 打印 It's less than 5 还是打印It's equal to 5??Top
2 楼alan118(The Server Side)回复于 2003-09-01 23:01:38 得分 0
vc6下的错误输出说明了一切:illegal else without matching if
if和else没有匹配
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int i=0;
cout<<"type a number and 'enter'"<<endl;
cin>>i;
if (i>5)
cout<<"it's greater than 5"<<endl;
else if(i<5)
cout<< "It's less than 5"<<endl;
else
cout<< "It's equal to 5 "<<endl;
cout<< "type a number and 'enter'"<<endl;
cin>>i;
if(i<10)
if(i>5)
cout<< "5<i<10"<<endl;
else if(i<=5)
cout<< "i<=5"<<endl;
else
cout<< "i>=10"<<endl;
system("PAUSE");
return 0;
}
Top
3 楼alan118(The Server Side)回复于 2003-09-01 23:02:10 得分 80
vc6下的错误输出说明了一切:illegal else without matching if
if和else没有匹配
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int i=0;
cout<<"type a number and 'enter'"<<endl;
cin>>i;
if (i>5)
cout<<"it's greater than 5"<<endl;
else if(i<5)
cout<< "It's less than 5"<<endl;
else
cout<< "It's equal to 5 "<<endl;
cout<< "type a number and 'enter'"<<endl;
cin>>i;
if(i<10)
if(i>5)
cout<< "5<i<10"<<endl;
else if(i<=5)
cout<< "i<=5"<<endl;
else
cout<< "i>=10"<<endl;
system("PAUSE");
return 0;
}
Top
4 楼webrabbit(猪头)回复于 2003-09-01 23:13:11 得分 0
谢过.Top
5 楼webrabbit(猪头)回复于 2003-09-01 23:15:39 得分 0
system("PAUSE");
return 0;
这二句不加,,也能调试成功,我是初学者,,请问.这二句代码代表了什么意思啊?Top
6 楼catface(峰)回复于 2003-09-02 18:37:02 得分 0
运行后产生 按任意键继续
就是暂停屏幕 好看清楚些
getchar() 就是等待输入 也是暂停屏幕的土办法
return 0么 因为正规的C++程序中 都是 int main 返回0 表示正常退出Top




