Code bị lỗi "expression must have bool type (or be convertible to bool)"

Em sai ở đâu ạ : Lỗi expression must have bool type (or be convertible to bool)

#include <iostream>
#include <string>

using namespace std;

struct info {
    int Paper_ID;
    string title;
    int yearrealease;
};

struct Publish {
    int Publisher_ID;
    string publisher;
};

struct node {
    info NPaper;
    node* pNext;
};

struct singleList {
    node* pHead;
    node* pTail;
};

void initializeList(singleList& l) {
    l.pHead = NULL;
    l.pTail = NULL;
}

node* createNode(info x) {
    node* p;
    p = new node;
    if (p == NULL)
        return NULL;
    p->NPaper = x;
    p->pNext = NULL;
    return p;
}

void insertHead(singleList& l, node* p)
{
    if (l.pHead == NULL)
    {
        l.pHead = p;
        l.pTail = p;
    }
    else
    {
        p->pNext = l.pHead;
        l.pHead = p;
    }
}


void InputList(singleList& l)
{
    int n;
    cout << "Quantity: ";
    cin >> n;

    info k;
    for (int i = 1; i <= n; i++)
    {
        cout << "+) Number " << i << ": " << endl;
        cout << "\n ID: ";
        cin >> k.Paper_ID;
        cout << "\n Title: ";
        cin.ignore();
        getline(cin, k.title);
        cout << "\n Year: ";
        cin >> k.yearrealease;
        //insertHead(l, createNode(k));
        insertHead(l, createNode(k));
    }
}

void OutputList(singleList& l)
{
    node* p = l.pHead;
    if (p == NULL)
    {
        cout << "List Empty";
        return;
    }
    cout << "Paper List" << endl;
    int dem = 1;
    while (p != NULL)
    {
        cout << dem << ") ID: " << p->NPaper.Paper_ID << endl;
        cout << "Title: " << p->NPaper.title << endl;
        cout << "Year: " << p->NPaper.yearrealease << endl;
        dem++;
        p = p->pNext;
    }
}

int main()
{
    singleList l;
    initializeList(l);

    while (l) {
        int n;
        cout << "1. Nhap danh n bai bao bang cach them vao dau sau do xuat danh sach vua nhap";
        cout << "6. End.";
        cout << "\n n: ";
        cin >> n;
        if (n == 6)
            break;
        else if (n == 1)
        {
            InputList(l);
            OutputList(l);
        }
    }
}

Thông báo lỗi nó chỉ thẳng vào dòng bị lỗi rồi, thế mà hỏi “sai ở đâu” nữa. :woman_facepalming::man_facepalming:

3 Likes

Học lại code cơ bản đi bạn à, thực sự đấy. Những thứ cơ bản của code như vòng lặp, điều kiện,… phải vững thì sẽ không hỏi mấy câu ngớ ngẩn thế này.

1 Like

thông báo lỗi để làm gì

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?