我正在创建一个图书档案计划,其中一位数据成员说这本书是否被阅读.但是我不能让程序在屏幕上写"是",所以我猜它永远不会改变,即使我在被问及是否读过这本书时也会说'Y'.谁能看到我做错了什么?
cout << "\n\tEnter title of book: ";
cin >> title;
cout << "\tEnter author of book: ";
cin >> author;
cout << "\tEnter genre of book (1. Crime, 2. Sports, 3. Science, 4. Drama): ";
cin >> choice;
switch(choice)
{
case 1: genre = crime; break;
case 2: genre = sports; break;
case 3: genre = science; break;
case 4: genre = drama; break;
}
cout << "\tEnter year of publication: ";
cin >> yearPublished;
cout << "\tHave you read the book? (Y/N): ";
cin >> ch;
if(toupper(ch) == 'Y')
{
haveRead == true;
}
else
{
haveRead == false;
}
Run Code Online (Sandbox Code Playgroud)
haveRead == true
Run Code Online (Sandbox Code Playgroud)
是比较,而不是作业.从两个子句中删除一个=
if(toupper(ch) == 'Y')
haveRead = true;
else
haveRead = false;
Run Code Online (Sandbox Code Playgroud)