主题:怎么把这代码的goto语句转换成循环语句和if语句???
[code=c]
#include <iostream>
using namespace std;
int main()
{
char a[]={65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
65+32,66+32,67+32,68+32,69+32,70+32,71+32,72+32,73+32,74+32,75+32,76+32,77+32,78+32,79+32,80+32,81+32,82+32,83+32,84+32,85+32,86+32,87+32,88+32,89+32,90+32};
char b[9999];
cin>>b;
int o=0;
int i;
int d=0;
abc: for(i=0;i<52;i++)
{
if(b[o]==a[i])
{
o=o++;
goto abc;
}
}
cout<<"你输入了"<<o<<"个字符"<<endl;
return 0;
}[/code]
怎么用循环和if来替代goto呢?
书上说最好不要用goto语句,这是为什么呢?本人新手,多谢解答!
还有能不能简化此代码呢???
#include <iostream>
using namespace std;
int main()
{
char a[]={65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
65+32,66+32,67+32,68+32,69+32,70+32,71+32,72+32,73+32,74+32,75+32,76+32,77+32,78+32,79+32,80+32,81+32,82+32,83+32,84+32,85+32,86+32,87+32,88+32,89+32,90+32};
char b[9999];
cin>>b;
int o=0;
int i;
int d=0;
abc: for(i=0;i<52;i++)
{
if(b[o]==a[i])
{
o=o++;
goto abc;
}
}
cout<<"你输入了"<<o<<"个字符"<<endl;
return 0;
}[/code]
怎么用循环和if来替代goto呢?
书上说最好不要用goto语句,这是为什么呢?本人新手,多谢解答!
还有能不能简化此代码呢???