gpt4 book ai didi

c++ - 陷入 while 循环 C++

转载 作者:太空宇宙 更新时间:2023-11-04 16:18:31 25 4
gpt4 key购买 nike

我是编程新手,我想知道是否有人可以帮助我解决这个问题?它似乎处于连续循环中,我一直在更改它并尝试不同的方法近一个小时,将不胜感激。

    #include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <iomanip>
#include "float.h"
#include <stack>

using namespace std;

using std::stack;

int _tmain(int argc, _TCHAR* argv[])
{

{
char treatment_types, anymore_treatments, anymore_visits, treatment_type[15], answer/*, ftype, wtype, ctype, etype, rtype, itype*/;
double levy = 15, fcharge, wcharge, ccharge, echarge, rcharge, icharge, cost, totalcost, totalincome;
int quantity, noofpatients, total_qtyf, total_qtyw, total_qtyc, total_qtye, total_qtyr, total_qtyi;


cout << "\n Enter treatment type (F,W,C,E,R,I) : ";
cin >> treatment_types;
cout << "\n Enter quantity of treatments : ";
cin >> quantity;




switch (treatment_types)
{
case 'F': fcharge = 27.50;
cost = fcharge;
total_qtyf = quantity;
cost = quantity*cost;
totalcost = fcharge + cost;
/*totalcost = fcharge * total_qtyf;*/
break;

case 'W': wcharge = 40.00;
cost = wcharge;
total_qtyw = quantity;
cost = quantity*cost;
totalcost = wcharge + cost;
/* totalcost = quantity + total_qtyw;*/
break;

case 'C': ccharge = 210.00;
cost = ccharge;
total_qtyc = quantity;
cost = quantity*cost;
totalcost = ccharge + cost;
/*totalcost = quantity + total_qtyc;*/
break;

case 'E': echarge = 25.00;
cost = echarge;
total_qtye = quantity;
cost = quantity*cost;
totalcost = echarge + cost;
/* totalcost = quantity + total_qtye; */
break;

case 'R': rcharge = 145.00;
cost = rcharge;
total_qtyr = quantity;
cost = quantity*cost;
totalcost = rcharge + cost;
/* totalcost = quantity + total_qtyr;*/
break;

case 'I': icharge = 7.50;
cost = icharge;
total_qtyi = quantity;
cost = quantity*icharge;
totalcost = cost + icharge;
/*totalcost = quantity + total_qtyi; */
break;
}

cout << "\n " << cost + 15;
/* do
{*/

cout << "\n\n""Any more treatments [Y/N] :";
cin >> answer;

while (answer == 'Y')
{
cout << "\nEnter treatment type( F,W,C,E,R,I) : ";
cin >> treatment_type;
cout << "\nEnter Quantity : ";
cin >> quantity;
cout << "\n " << cost * quantity;
cout << "\n\n""Any more treatments [Y/N] :";
cin >> answer;
}
while (answer == 'N')
{
cout << "Anymore visits? [Y/N]: ";
cin >> answer;
}
while (answer == 'N')
{
cout << "Your bill is : " << totalcost << endl;
}
{ while (answer == 'Y')
cout << "\nEnter treatment type( F,W,C,E,R,I) : ";
cin >> treatment_type;

}

}

//while (true);
_getche();
return 0;

}
//}

最佳答案

        while (answer == 'N')
{
cout << "Your bill is : " << totalcost << endl;
}

如果进入这个循环,它怎么可能退出?

也许您打算让 while 成为 if

还有:

        {   while (answer == 'Y')
cout << "\nEnter treatment type( F,W,C,E,R,I) : ";
cin >> treatment_type;

}

您可能想将 while 移到 block 外:

        while (answer == 'Y') {
cout << "\nEnter treatment type( F,W,C,E,R,I) : ";
cin >> treatment_type;
}

关于c++ - 陷入 while 循环 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19865619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com