Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;而声明获胜';不要在第一次之后就停止重复_C++_Loops_While Loop - Fatal编程技术网

C++ C++;而声明获胜';不要在第一次之后就停止重复

C++ C++;而声明获胜';不要在第一次之后就停止重复,c++,loops,while-loop,C++,Loops,While Loop,我试图为一个编程类编写代码,出于某种原因,我发现只有当您对问题的第一个回答是“n”时,它才会重复。否则,无论您输入什么,它都会继续重复 while (again == 'y') { cout << endl << endl; //Header Art cout << " .\'( .-./( )\\.-. .\'( /`-. /`-. .-,.-.,-. )\\.--. \n"; cout &l

我试图为一个编程类编写代码,出于某种原因,我发现只有当您对问题的第一个回答是“n”时,它才会重复。否则,无论您输入什么,它都会继续重复

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行打开,但从不关闭。。