c++ - 即使它是真正的 C++,我的 while 循环也不会开始
问题描述
我的代码不想阅读评论之间的内容,只是跳过它,即使电话和 snn 设置为小于代码内部
int num = 1;
while (num > 0 && num < 2) {
num = 1;
string first = "chicken";
string last = "salad";
string full = "chicken salad";
int phone = 1;
int snn = 1;
cout << "enter your first name: ";
cin >> first;
cout << "enter your last name: ";
cin >> last;
full = first + " " + last;
cout << phone;
// works all the way to here then doesnt read the while
while (phone < 1000000000 && phone > 9999999999) {
cout << "enter 10 digit phone nmber (with no dashes or parenthesis): ";
cin >> phone;
}
while (snn < 100000000 && snn > 999999999) {
cout << "enter 9 digit snn <with no dashes>: ";
cin >> snn;
}
// starts working again here
cout << "\n\tT H A N K Y O U\n\n";
system("pause");
return 0;
}
解决方案
在两个 while 循环中,您都有一个&&
代替||
,这意味着您要求phone
同时小于 1000000000
和 大于 9999999999
,这将始终返回false
。
推荐阅读
- java - 无法加载实体元数据
- mongodb - 仅当存在时才匹配 mongodb 查询的变量
- php - 用 Guzzle 重写 curl(文件上传) - PHP
- sql - XML 数据加载到 SQL Server 特殊 XML 格式
- sql - PostgreSQL 创建引用不存在表的函数
- android - PreferencesFragment 和 MVVM 架构
- java - 使用 Docx4j 从 Docx 文件中读取文本
- excel - 使用 VBA 将 PDF 对象插入我的工作表时,它不显示任何图标,之后我无法保存我的工作簿
- angular - 角材质徽章位置
- python - 基于另一个查询集过滤查询集