C++ C++;而声明获胜';不要在第一次之后就停止重复
我试图为一个编程类编写代码,出于某种原因,我发现只有当您对问题的第一个回答是“n”时,它才会重复。否则,无论您输入什么,它都会继续重复C++ C++;而声明获胜';不要在第一次之后就停止重复,c++,loops,while-loop,C++,Loops,While Loop,我试图为一个编程类编写代码,出于某种原因,我发现只有当您对问题的第一个回答是“n”时,它才会重复。否则,无论您输入什么,它都会继续重复 while (again == 'y') { cout << endl << endl; //Header Art cout << " .\'( .-./( )\\.-. .\'( /`-. /`-. .-,.-.,-. )\\.--. \n"; cout &l
while (again == 'y')
{
cout << endl << endl;
//Header Art
cout << " .\'( .-./( )\\.-. .\'( /`-. /`-. .-,.-.,-. )\\.--. \n";
cout << " ,\') \\ ) ,\' ) ,\' ,-,_) ,\') \\ ) ,\' _ \\ ,\' _ \\ ) ,, ,. ( ( ._.\' \n";
cout << "( \'-\' ( ( .-, ( ( . __ ( /(/ / ( \'-\' ( ( \'-\' ( \\( |( )/ `-.`. \n";
cout << " ) .-. ) ) \'._\\ ) ) \'._\\ _) ) ( ) _ ) ) ,_ .\' ) \\ ,_ ( \\ \n";
cout << "( , ) \\ ( , ( ( , ( ( .\'\\ \\ ( ,\' ) \\ ( \' ) \\ \\ ( ( \'.) ) \n";
cout << " )/ )/ )/ ._.\' )/\'._.\' )/ )/ )/ )/ )/ )/ )/ \'._,_.\' \n";
cout << endl;
//Variables
int TuitionBill, BoardBill, TotalBill;
char tuition, board, again;
cout << "Welcome to Hogwarts School of Witchcraft and Wizardry!\n\n";
cout << "Please input 'I' if you are in-country or 'O' if you are out of country\n";
cin >> tuition;
cout << endl << endl;
cout << "Please input 'Y' if you will be staying in one of the four houses\n and 'N' if you will be hiding out in the Shrieking Shack.\n";
cin >> board;
cout << endl << endl;
switch (tuition)
{
case 'I':
TuitionBill = 3000;
if (board == 'Y')
BoardBill = 2500;
else if (board == 'N')
BoardBill = 0;
TotalBill = TuitionBill + BoardBill;
cout << "Your total bill for the semester is $" << TotalBill;
break;
case 'O':
TuitionBill = 4500;
if (board == 'Y')
BoardBill = 3500;
else if (board == 'N');
BoardBill = 0;
TotalBill = TuitionBill + BoardBill;
cout << "Your total bill for the semester is $" << TotalBill;
break;
default:
cout << "That answer is invalid. Please input only an 'I' or an 'O.'";
}
cout << endl << endl;
cout << "Would you like to run the program again? (y/n)\n";
cin >> again;
while(同样=='y')
{
cout请再次删除循环中的定义。
它可以防止在更新时在的条件下再次计算。这不应该是主要问题,但我认为中的分号是if(board='N');
应该被删除。你试过调试你的代码吗?你发现了什么?请发布一个。这不是完整的代码,所以很难说。但是,你应该以尽可能高的警告级别编译,并注意所有的警告。变量中应该有一些东西。你提到过吗循环。您的第一个语句是循环。块在第2行打开,但从不关闭。。