项目代码同时正确和不正确地注册'N'

Project code is registering 'N' correctly and incorrectly at the same time

本文关键字:正确地 注册 不正确 代码 项目      更新时间:2023-10-16

我正在为学校做一个项目,我们必须创建一个循环报价系统。我正在尝试获取代码,以提示用户询问他们是否想做其他报价。

如果用户输入'n'代码执行结束程序语句以及不正确的响应语句。任何帮助将不胜感激,代码在下面,输出在代码以下。

if (runQuote = 'N' || 'n') {
    cout <<"Thank you for using this program.  Goodbye. n";
} else {
   " ";
}
if (runQuote != 'Y' || 'y' || 'N' || 'n') {
    cout << "Sorry but the response you answered is not valid, 
      Would you like to process another quote (Y/N)?n";
    cin >> runQuote;
}

如果我在提示后输入'n',则输出是:

  Thank you for using this program.  Goodbye.
  Sorry but the response you answered is not valid,
    Would you like to process another quote (Y/N)?

您的问题在您的if语句中。而不是

if (runQuote = 'N' || 'n')

你应该有

if (runQuote == 'N' || runQuote == 'n')

'n'在您的原始代码中评估为true

如果用户输入'n'或'n',您希望程序退出。因此您的支票应该是这样:

if ((runQuote == 'N') || (runQuote == 'n'))

最好花时间在一本好书上,而不是猜测一种语言的语法,尤其是像c 这样的语言。