【发布时间】:2021-04-17 18:12:02
【问题描述】:
我的代码不想读取 cmets 之间的内容,只是跳过它,即使 phone 和 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;
}
【问题讨论】:
-
phone被初始化为1,使phone > 9999999999始终为假。snn也一样。你是说还是 (||)? -
如果您在调试器中逐步解决问题,您会在一秒钟内自己发现问题。
-
和 > 9999999999是多少?你需要
||代替&&。 -
phone怎么可能是 和 > 9999999999? -
我完全忘记了 ||命令谢谢你我习惯在数字里面而不是在外面
标签: c++ while-loop