Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > помогите, найти ошибку в программе


Автор: gerda 20.11.2005, 18:47
Помогите, пожалуйсто, это програмка работает, НО можно ввести только одно число.... потом появляется таблица - press any key to continue.... ты нажимаеш и тебя просто викидивают..... smile


Код

#include <stdio.h>
#include <stdlib.h>

// checking if the cell is accessible by knight
bool movecell(int cellx, int celly, int posx,int posy)    // kpos - position of knight
{                                        // cell - cell to check
    if ((cellx == posx-2 && celly == posy-1) ||
        (cellx == posx-2 && celly == posy+1) ||

        (cellx == posx+2 && celly == posy-1) ||
        (cellx == posx+2 && celly == posy+1) ||

        (cellx == posx+1 && celly == posy+2) ||
        (cellx == posx-1 && celly == posy+2) ||

        (cellx == posx+1 && celly == posy-2) ||
        (cellx == posx-1 && celly == posy-2) )
        
        return true;

    return false;
}

void draw(int ver,int hor)
{
    printf ("   a  b  c  d  e  f  g  h\n");
    for (int i=0;i<8;i++)
    {
        printf("%d",i+1);
        for (int k=0;k<8;k++)
            printf("  %s", movecell(i,k,hor,ver)?"x":
                    (i==hor && k==ver?"*":"0") );
        printf("\n");
    }
}

int main(int argc, char* argv[])
{
    // asking knight's position
    
    char s[3];
    printf("Enter knight's coordinates:");
    fgets(s,3,stdin);
    
    int hor,ver;
    ver = (int)s[0] - 97;    // 97 - code of 'a'
    if (ver<0 && ver>7){
        printf("\n!error! wrong argument\n");
        return 0;
    }
    hor = atoi(&s[1])-1;
    if (hor<0){
        printf("\n!error! wrong argument\n");
        return 0;
        
    }
    draw(ver,hor);
    system("pause");
    return 0;
}

Автор: Voldemar2004 20.11.2005, 19:12
Подключи #include <conio.h>

Код

}
draw(ver,hor);
system("pause");
return 0;
getch();
}
если я правильно понял, то это то, что тебе нужно.

Автор: gerda 20.11.2005, 19:20
это не помогает, всеравно меня викидивают smile

Автор: Mayk 20.11.2005, 20:30
А тебе что надо? Чтобы не выкидывало? Тогда
поставь после int main(...){
строку
do{
перед
return 0;
пропиши
printf("press Q to quit, any other to continue");
}while(getch() != 'Q' )
и пропиши в начале
Цитата(Voldemar2004 @ 20.11.2005, 23:12)
#include <conio.h>


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)