问题1 没有结束输出,应改为:
if(counter==10)
cout<<"Ahah! You know the secret.\n";
if(counter>10)
cout<<"You should be able to do better.\n";
if(counter<10)
cout<<"Either you know the secret or you got lucky!"
<<endl;
if(counter==10)
cout<<"Ahah! You know the secret.\n";
if(counter>10)
cout<<"You should be able to do better.\n";
if(counter<10)
cout<<"Either you know the secret or you got lucky!"
<<endl;
解决方案 »
- CFtpFileFind类FindFile问题
- 如何用文件打开功能得到所选择的多个文件的文件名?
- 向大家推荐一款企业即时通讯与协作软件,非常适合于小型的开发团队中使用.
- 请问:利用SMTP协议发送邮件后,如何通过pop协议收取特定的邮件?
- 如何用vc++实现对cpu,内存使用情况的监控?
- 怎样让连接断开不出现一个TIME_WAIT?
- 简单问题:
- 请教各位老大,在DB-LIBRARY中如何使用存贮过程,并返回记录集(不返回的也要)
- 怎样实现 IE中 历史纪录 那样的切分窗口
- 我想在Static Control上使用SetCursor,怎么用?
- 关于认证考试的问题
- 怎么样判断一个字符串是否是合法的路径??急.......
if(counter==10)
cout<<"Ahah! You know the secret.\n";
if(counter>10)
cout<<"You should be able to do better.\n";
if(counter<10)
cout<<"Either you know the secret or you got lucky!\n"cout<<endl;问题2
result 声明为int 所以输入小数,自动取整,(不是四舍五入)
输入0.XXX时 result = 0;问题3
getchar()
<<endl;
和语句cout<<"Either you know the secret or you got lucky!";
cout<<endl;有什么不同?
问题2:result即使为0也不应该进入无限循环啊
int istream::getint(char * buffer) // returns length
{
int base, i;
int c;
int fDigit = 0;
int bindex = 1; if (x_flags & ios::dec)
base = 10;
else if (x_flags & ios::hex)
base = 16;
else if (x_flags & ios::oct)
base = 8;
else
base = 0; if (ipfx(0))
{
c=bp->sgetc();
for (i = 0; i<MAXLONGSIZ-1; buffer[i] = (char)c,c=bp->snextc(),i++)
{
if (c==EOF)
{
state |= ios::eofbit;
break;
}
if (!i)
{
if ((c=='-') || (c=='+'))
{
bindex++;
continue;
}
}
if ((i==bindex) && (buffer[i-1]=='0'))
{
if (((c=='x') || (c=='X')) && ((base==0) || (base==16)))
{
base = 16; // simplifies matters
fDigit = 0;
continue;
}
else if (base==0)
{
base = 8;
}
}
// now simply look for a digit and set fDigit if found else break if (base==16)
{
if (!isxdigit(c))
break;
}
else if ((!isdigit(c)) || ((base==8) && (c>'7')))
break; fDigit++;
}
if (!fDigit)
{
state |= ios::failbit; // <= 运行到这里时,因为不是数字,会设置错误状态,下次在获取输入时因为存在错误状态,直接跳过了,因此,再次接收输入时,必须清除掉错误状态。
while (i--)
{
if(bp->sputbackc(buffer[i])==EOF)
{
state |= ios::badbit;
break;
}
else
state &= ~(ios::eofbit);
}
i=0;
}
// buffer contains a valid number or '\0'
buffer[i] = '\0';
isfx();
}
if (i==MAXLONGSIZ)
{
state |= ios::failbit;
}
return base;
}