下雨编程问题,老出错啊,求教
#include<iostream.h>#include <ctype.h>
#include<stdlib.h>
using namespace std ;
void main()
{char flag;
while(1)
{cout<<"现在正在下雨吗?Y/N:";
cin>>flag;
if(toupper(flag)=='Y') //toupper将小写转化为大写字母
{
cout<<"现在正在下雨";
break;
}
if(toupper(flag)=='N')
{
cout<<"现在没有下雨";
break;
}
}
} 这个兄弟,我给你调试一下,我猜你是不清楚break语句怎么使用!
如果第一个if使用了break,整个语句就结束了,所以当你输入N的时候,第一个if语句不正确,然后直接break,直接退出程序了。
下面程序的调试是正确的:
#include<iostream.h>
#include<ctype.h>
#include<stdlib.h>
using namespace std;
void main()
{
char flag;
while(1){
cout<<"现在正在下雨吗?Y/N:\n";
cin>>flag;
if(toupper(flag)=='Y') //toupper将小写转化为大写字母
cout<<"现在正在下雨\n";
else if(toupper(flag)=='N')
cout<<"现在没有下雨\n";
break;
}
}
using namespace std;
把这句删了,没用的。 #include<iostream>
using namespace std ;
这样就对。 小文盲 发表于 2012-8-14 11:52 static/image/common/back.gif
#include
using namespace std ;
这样就对。
hh呵呵,我木有学过C++,我是C,不过我知道有这个申明。
页:
[1]