else 语句错误 w/declaration (C++)
Error w/declaration on else statement (C++)
#include <iostream>
using namespace std;
// Range of numbers, handles input in which the first number is smaller than the second.
int main()
{
int max = 10;
int min = 0;
while(cin >> min)
{
if(min<max)
{
++min;
cout << "The number inputted is well in the RANGE: " << min << endl;
else
{
cout << "The number inputted is not in the RANGE: " << max << endl;
}
}
} // End of if.
}
这是怎么回事?为什么这不起作用?我是 Stack 的新手,所以我尝试发布这个,有什么帮助吗?
您应该在开始 else 部分之前结束 if :
int main()
{
int max = 10;
int min = 0;
while(cin >> min){
if(min<max){
++min; //dont understand why do you do this !
cout << "The number inputted is well in the RANGE: " << min << endl;
} // End of if.
else{
cout << "The number inputted is not in the RANGE: " << max << endl;
}
}
}
#include <iostream>
using namespace std;
// Range of numbers, handles input in which the first number is smaller than the second.
int main()
{
int max = 10;
int min = 0;
while(cin >> min)
{
if(min<max)
{
++min;
cout << "The number inputted is well in the RANGE: " << min << endl;
else
{
cout << "The number inputted is not in the RANGE: " << max << endl;
}
}
} // End of if.
}
这是怎么回事?为什么这不起作用?我是 Stack 的新手,所以我尝试发布这个,有什么帮助吗?
您应该在开始 else 部分之前结束 if :
int main()
{
int max = 10;
int min = 0;
while(cin >> min){
if(min<max){
++min; //dont understand why do you do this !
cout << "The number inputted is well in the RANGE: " << min << endl;
} // End of if.
else{
cout << "The number inputted is not in the RANGE: " << max << endl;
}
}
}