올바르게 반복되지 않음

그녀는

이 코드의 목적은 기본적인 도서관 체크인 체크 아웃 시스템이며, 스캐너를 사용하여 ISBN 번호 인 바코드를 입력 한 다음 프로그램이 내 .txt 데이터베이스를보고 도서 이름을 검색합니다. 그런 다음 책을 확인하고 싶은지 물어보고 학생 ID 번호를 묻고 ISBN, out / in, id 번호 및 현재 시간을 FILE로 출력합니다. 프로그램은 처음에는 훌륭하게 작동하지만 바코드를 입력 한 후 다른 책을 확인하려고하면 작동이 중지됩니다. 그것은 단지 정지에서 움직일 수없는 입력을 취하지 않을 것입니다.

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;

int main()
{

char variable = 1;
ifstream infile;
ofstream outfile;
infile.open("Library_Database.txt");
outfile.open("Library_Checkout.txt", ios::app);

do {
    char variable;
    cout << "SETSUCON MANGA LIBRARY DATABASE\n\n" << setw(45) << "For Check-Out please enter: O or o\n" << setw(45) << "For Check-In please enter: I or i\n" << setw(45) << "For Assistance please enter: H or h\n" << setw(45) << "To close this program please enter: Q or q\n" << setw(50) << "Enter an option: ";
    cin >> variable;
    cout << "\n";

    if (variable == 'O' || variable == 'o'){

        double search;
        double ISBN = 0;
        string bookName;

        cout << "Please Scan Barcode: ";
        cin >> search; //runs fine one time then gets stuck here after I input the ISBN number the second time 

        while (ISBN != search){
            infile >> ISBN >> bookName;
        }
        cout << "You would like to check out: " << bookName << "?" << endl;

        string idNumber;
        char yesOrNo;
        cout << "Yes or No (Y or N): ";
        cin >> yesOrNo;
        if (yesOrNo == 'Y' || yesOrNo == 'y'){
            cout << "Please input Student ID number or Badge ID Number: ";
            cin >> idNumber;
            cout << endl;
            time_t now = time(0);
            char* dt = ctime(&now);

            outfile.setf(ios::fixed);
            outfile.precision(0);

            outfile << search << std::resetiosflags(std::ios::showbase) << setw(12) << idNumber << setw(4) << "out" << setw(30) << dt << endl;
        }
        else{
            cout << endl << "\n";
            continue;
        }
    }

    else if (variable == 'I' || variable == 'i'){

        double search;
        double ISBN = 0;
        string bookName;

        cout << "Please Scan Barcode: ";
        cin >> search; //runs fine one time then gets stuck here after I input the ISBN number the second time

        while (ISBN != search){
            infile >> ISBN >> bookName;
        }
        cout << "You would like to check in: " << bookName << "?" << endl;

        string idNumber;
        char yesOrNo;
        cout << "Yes or No (Y or N): ";
        cin >> yesOrNo;
        if (yesOrNo == 'Y' || yesOrNo == 'y'){
            cout << "Please input Student ID number or Badge ID Number: ";
            cin >> idNumber;
            cout << endl;
            time_t now = time(0);
            char* dt = ctime(&now);

            outfile.setf(ios::fixed);
            outfile.precision(0);

            outfile << search << std::resetiosflags(std::ios::showbase) << setw(12) << idNumber << setw(4) << "in" << setw(30) << dt << endl;
        }
        else{
            cout << endl << "\n";
            continue;
        }
    }
    else if (variable == 'H' || variable == 'h'){
        cout << "This program was written Shea Transue.\n" << "For Assistance Please Contact Shea Transue at 484-264-5863\n\n";
    }
    else if (variable == 'Q' || variable == 'q') {
        cout << "Thank you for using the SETSUCON LIBRARY DATABASE.\n" << "For assistance please Call or Text Shea Transue at 484-264-5864\n\n";
        break;
    }
    else {
        cout << variable << " is not a valid option. Try again\n\n";
    }

} while (variable != 'Q' || variable != 'q');

infile.close();
outfile.close();
return 0;
}
감자 튀김

라이브러리 데이터베이스를 열고 운영자 infile와 함께 스캔 >>하지만 infile.seekg( 0, std::ios::beg ).

책을 찾을 수 없으면 while루프가 종료되지 않습니다. 중간 어딘가에서 데이터베이스 스캔을 시작하기 때문에 첫 번째 이후의 책은 찾지 못할 수 있습니다.

이 시도:

do {
    cout << "Please Scan Barcode: ";
    cin >> search; //runs fine one time then gets stuck here after I input the ISBN number the second time 

    infile.clear();
    infile.seekg( 0, std::ios::beg );
    while ( infile && ISBN != search){
        infile >> ISBN >> bookName;
    }
    if ( ! infile ) {
        std::cout << "The book was not found in the database.\n";
    }
} while ( ! infile );

또한 프로그램을 별도의 함수로 나누고 ( "팩터링") 각 함수를 개별적으로 테스트하십시오.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

asp : repeater에서 <a> 태그가 올바르게 반복되지 않음

분류에서Dev

반복이 올바르게 계산되지 않습니다.

분류에서Dev

내 양식이 올바르게 반복되지 않습니다.

분류에서Dev

올바르게 계산하지 않음

분류에서Dev

> = 올바르게 작동하지 않음

분류에서Dev

DecimalFormat이 소수점 두 자리로 올바르게 반올림되지 않음

분류에서Dev

뷰 모델이 올바르게 바인딩되지 않음 C #

분류에서Dev

바람둥이가 올바르게 배포되지 않음

분류에서Dev

음수 값이 올바르게 인쇄되지 않음

분류에서Dev

angular-일부 양식 입력에서 $ index가 올바르게 반복되지 않음

분류에서Dev

최대화 된 소유 양식이 올바르게 복원되지 않음

분류에서Dev

border-collapse시 셀 너비 속성이 올바르게 복사되지 않음

분류에서Dev

나머지 통화가 컬로 올바르게 반환되지 않음

분류에서Dev

Google지도가 올바르게 표시되지 않음

분류에서Dev

배경 이미지가 올바르게 표시되지 않음

분류에서Dev

FancyBox 이미지가 올바르게로드되지 않음

분류에서Dev

PHP 에코가 <div>를 올바르게 반환하지 않음

분류에서Dev

반응 디스플레이가 올바르게 업데이트되지 않음

분류에서Dev

반응 후크, 상태가 올바르게 변경되지 않음

분류에서Dev

반응 양식 입력 값이 올바르게 표시되지 않음

분류에서Dev

SELECT에 기반한 INSERT가 PostGreSQL로 올바르게 삽입되지 않음

분류에서Dev

PHP 5.6 : password_verify 함수가 올바르게 반환되지 않음

분류에서Dev

C # Serialization Woes-Int Array가 올바르게 저장 / 반환되지 않음

분류에서Dev

Ubuntu 20.04가 올바르게 부팅되지 않음

분류에서Dev

테이블 키가 올바르게 정렬되지 않음

분류에서Dev

Docker swarm이 Dockerfile에서 올바르게 빌드되지 않음

분류에서Dev

underscorejs _uniq가 올바르게 필터링되지 않음

분류에서Dev

Sumif가 올바르게 계산되지 않음

분류에서Dev

div 행이 올바르게 정렬되지 않음

Related 관련 기사

  1. 1

    asp : repeater에서 <a> 태그가 올바르게 반복되지 않음

  2. 2

    반복이 올바르게 계산되지 않습니다.

  3. 3

    내 양식이 올바르게 반복되지 않습니다.

  4. 4

    올바르게 계산하지 않음

  5. 5

    > = 올바르게 작동하지 않음

  6. 6

    DecimalFormat이 소수점 두 자리로 올바르게 반올림되지 않음

  7. 7

    뷰 모델이 올바르게 바인딩되지 않음 C #

  8. 8

    바람둥이가 올바르게 배포되지 않음

  9. 9

    음수 값이 올바르게 인쇄되지 않음

  10. 10

    angular-일부 양식 입력에서 $ index가 올바르게 반복되지 않음

  11. 11

    최대화 된 소유 양식이 올바르게 복원되지 않음

  12. 12

    border-collapse시 셀 너비 속성이 올바르게 복사되지 않음

  13. 13

    나머지 통화가 컬로 올바르게 반환되지 않음

  14. 14

    Google지도가 올바르게 표시되지 않음

  15. 15

    배경 이미지가 올바르게 표시되지 않음

  16. 16

    FancyBox 이미지가 올바르게로드되지 않음

  17. 17

    PHP 에코가 <div>를 올바르게 반환하지 않음

  18. 18

    반응 디스플레이가 올바르게 업데이트되지 않음

  19. 19

    반응 후크, 상태가 올바르게 변경되지 않음

  20. 20

    반응 양식 입력 값이 올바르게 표시되지 않음

  21. 21

    SELECT에 기반한 INSERT가 PostGreSQL로 올바르게 삽입되지 않음

  22. 22

    PHP 5.6 : password_verify 함수가 올바르게 반환되지 않음

  23. 23

    C # Serialization Woes-Int Array가 올바르게 저장 / 반환되지 않음

  24. 24

    Ubuntu 20.04가 올바르게 부팅되지 않음

  25. 25

    테이블 키가 올바르게 정렬되지 않음

  26. 26

    Docker swarm이 Dockerfile에서 올바르게 빌드되지 않음

  27. 27

    underscorejs _uniq가 올바르게 필터링되지 않음

  28. 28

    Sumif가 올바르게 계산되지 않음

  29. 29

    div 행이 올바르게 정렬되지 않음

뜨겁다태그

보관