卡在链表中的无限 Do-while 循环中



大家好,我正在输入教授布置的作业,基本上只是为酒店类型的服务开账单。我已经完成了链表,我所有的计算和输出都是根据需要完成的。但是当用户输入为"是"或"是"以继续时,我得到了一个无限循环。

#include <iostream>
using namespace std;
int main()
{
struct nodeType
{
double adults, children, costA, costC, dessert, room, tt, deposit;
nodeType *next, *link;
};
{
nodeType *first,*newNode,*last;
int num;
cout << "Casewell Catering and Convention Service Final Billn" << endl;
//cout << "Enter the number of this set: ";
//cin >> num;
// bool choice = true;
char ch;
first = NULL;
do
{
newNode = new nodeType;
newNode->link = NULL;
cout << "Number of Adults: ";
cin >> newNode -> adults;
cout<< "Number of Children: ";
cin >> newNode -> children;
cout<< "Cost Per Adult without dessert:     $";
cin >> newNode -> costA;
cout<< "Cost Per Child without dessert:     $" << (newNode -> children) *(newNode -> costA) * 0.60 << " (60% of the Adult's meal)" << endl;
cout<< "Cost per dessert:       $";
cin >> newNode -> dessert;
cout<< "Room fee:       $";
cin >> newNode -> room;
cout<< "Tips and tax rate:      $";
cin >> newNode -> tt;
cout << "" << "n" << endl;
//*********CALCULATIONS********************
cout << "Total cost for adult meals:        $" << (newNode -> adults) * (newNode -> costA) << endl;
cout << "Total cost for child meals:        $" << (newNode -> children) *(newNode -> costA) * 0.60 << endl;
cout << "Total cost for dessert:            $" << ((newNode -> adults) + (newNode -> children)) * (newNode -> dessert) << endl;
cout << "Total food cost:                 $" <<(newNode -> adults) * (newNode -> costA) +
(newNode -> children) *(newNode -> costA) * 0.60 +
((newNode -> adults) + (newNode -> children)) * (newNode -> dessert)<< endl;
cout << "Plus tips and tax:                $" << newNode -> tt * ((newNode -> adults) * (newNode -> costA) +
(newNode -> children) *(newNode -> costA) * 0.60 +
((newNode -> adults) + (newNode -> children)) * (newNode -> dessert)) << " (Does NOT Include Room Fee)" << endl;
cout << "Plus room fee:                    $" << (newNode -> room) << endl;
//  cout << "Less Deposit:                     $" <<
if(first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
cout << "Would you like to continue?(yes/no)" << endl;
cin >> ch;
} while (ch =='y' || ch == 'Y'); // end of while loop
}
return 0;
}

while(ch =='y' || ch == 'Y');替换为while(ch =="y" || ch == "Y" || ch=="yes" || ch=="Yes");

我想这就是你的意思。你不是很清楚,但是如果你想让"是"或"是"工作,你必须检查输入的"是"和"是">

编辑:另外,将"ch"更改为字符串:)

相关内容

  • 没有找到相关文章

最新更新