Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[3345] 무한 루프에 빠집니다..
로터스 [lotus11] 1281 읽음    2004-05-06 00:44
피보나치 구하는 프로그램인데요..
메인에서 x 또는 X누르면 빠져나오게 프로그래밍 했는데
x 또는 X누르면 무한루프에 빠지네요..
이렇게도 해보고 저렇게도 해봤는데, 계속 무한 루프에...
뭐가 잘못된 걸까요..?

#include <iostream>
#include <vector>
#include <string>

using namespace std;

// 함수 선언부
const vector<int>* fib( int );
inline bool is_ok(int);
void display_message(const string &, int);

int main()
{
    int input;
   
    cout << "Enter a number(If you want to exit a program, push 'x') : ";
    cin >> input;
   
    // x나 X를 누를때까지 루프 반복
    while(input != 'x' || input != 'X'){
        // 함수의 컨테이너의 반환값을 받는다
        const vector<int> *ppp = fib(input);   
   
        // 객체 출력
        for(int i=0; i<input; ++i)
            cout << (*ppp)[i] << ' ';
       
        cout << "Enter a number(If you want to exit a program, push 'x') : ";
        cin >> input;
    }
    return 0;
}

inline bool is_ok(int n)
{
    const int max_size = 1024;
    const string msg( "Requested size isn't supported" );

    if( n <=0 || n > max_size ){
        display_message( msg, n );
        return false;
    }
    return true;
}


const vector<int>* fib( int n )
{
    static vector<int> elem;
    if( ! is_ok(n) ){
        return 0;
    }

    for( int ix = elem.size(); ix < n; ++ix ){
        if( ix == 0 || ix == 1 )
            elem.push_back(1);
        else {
            elem.push_back( elem[ix-1] + elem[ix-2] );
        }
    }
   
    return &elem;
}

void display_message(const string &msg, int)
{
    cout << msg << endl;
}

+ -

관련 글 리스트
3345 무한 루프에 빠집니다.. 로터스 1281 2004/05/06
4412     Re:무한 루프에 빠집니다.. 김시환 1270 2004/05/06
4411     Re:무한 루프에 빠집니다.. 김시환 1249 2004/05/06
4410     Re:무한 루프에 빠집니다.. 로터스 1243 2004/05/06
4409     Re:무한 루프에 빠집니다.. 복창순 1313 2004/05/06
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.