项目代码同时正确和不正确地注册'N'
Project code is registering 'N' correctly and incorrectly at the same time
我正在为学校做一个项目,我们必须创建一个循环报价系统。我正在尝试获取代码,以提示用户询问他们是否想做其他报价。
如果用户输入'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 这样的语言。
相关文章:
- 如何正确地将分支添加到已存在的树中
- 如何正确地将带有指针的数组传递给函数
- 如何正确地推回然后遍历堆中对象的向量?
- 我是否不正确地集中了这些字符数组?
- 如何通过另一个对象中的命令正确地从一个对象返回数据
- 我怎样才能通过友谊正确地履行我的职能?
- C++:如何正确地将 deque::front() 返回的变量从函数中传递出去?
- 我应该如何正确地将packaged_task移动到 lambda?
- 如何正确地将SHA1CryptoServiceProvider转换为c ++?
- 如何正确地对 constexpr 函数进行单元测试
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 如何正确地将boost::asio::buffers_iterator转换为InputIterator
- 如何正确地检查变量char中包含的字母
- 当试图交换可变模板类时,如何正确地重载operator=
- 如何正确地将 boost::optional<std::chrono::d uration> 作为函数参数?
- 如何在C++中正确地将我的语言字符输出到HTML文件中
- 如果我的类正确地管理了一个资源,那么拥有智能的poointer有什么意义
- 如何正确地编写这些条件,以便它们在控制台中工作
- 正确地编写一个类,并将pthread与vlc库和c++一起使用
- 项目代码同时正确和不正确地注册'N'