本文介绍了用户将char赋予整数时,为什么程序崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
假设该程序

Hello!
suppose that program

void main()
{
oop:
    int a;
    for(int i=0; i<5; i++)
    {
        cout<<"ABC"<<endl;;
    }
    cout<<"Press 1 to display again"<<endl;
    cin>>a;
c:
    if(a==1)
    {
        goto oop;
    }
    getch();
}


现在,当我给"a"一个数值时,程序可以很好地进行……但是当我给它一个字符时…… a,b,z等,然后屏幕开始闪烁,并无限循环运行.
我知道ASCII码和我尝试了这种情况


now, when i give a numeric value to ''a'', then program goes on nicely...but when i give it a character...like; a,b,z etc then the screen starts to blink and infinite loop runs.
i know ASCII codes & i hv tried the condition

else if(a>100||a<0)
{
    cout<<"Try again";
    goto c;
}


但它仍然对我不起作用.


but it still doesn''t work for me.
please help me out sir!

推荐答案



这篇关于用户将char赋予整数时,为什么程序崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 06:24