使用转到

时间:2017-03-11 16:13:32

标签: c++ visual-c++

这是我查找字符串回文的代码。 初始执​​行完美。 但是当再次执行程序时,它会转到标签,并跳过cin语句并直接执行所有操作,最后到达终点。 当我在c ++ 6.0中使用它时,这并没有发生,但是在visual studio 2015中发生了 在此先感谢您的帮助。

#include "stdafx.h"
#include<iostream>

using namespace std;

void main()
{
    char string[100], ch;
    int x, i, j, flag = 0;
label:
    cout << "Enter a string. Max Length 99 : ";
    cin.getline(string, 100);
    x = strlen(string);
    cout << "Checking For Palindrome...........";
    for (long i = 0; i < 5000000; ++i)
    {
        cout << "";
    }
    cout << endl;
    for (i = 0, j = x - 1; i < x / 2; ++i, --j)
    {
        if (string[i] == string[j])
            continue;
        else
        {
            flag = 1;
            break;
        }
    }
    if (flag == 1)
        cout << "The String You Entered Is Not A Palindrome";
    else
        cout << "The String You Entered Is A Palindrome";
    cout << "\nDo you want to execute again? (Y/N)";
    cin >> ch;
    if (ch == 'y' || ch == 'Y')
         goto label;
    else
         cout << "See You Later :)";
}

0 个答案:

没有答案