2015-06-20 110 views
-2
#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新手,所以我尝试发布这个,呃有什么帮助?错误W于else语句/声明(C++)

+0

怎么不是这方面的工作?请更精确。 – chris

+0

如果这是你的实际代码,看看他们不匹配正确的括号(现在,我已经清理您的格式) –

回答

2

您应该结束了,如果你开始你的其他部分之前:

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; 
    } 
    }  
} 
+0

由于它工作得很好,我想我忽视的一部分,我认为我们没有需要结束ifs。谢谢。 – Seeist

+0

欢迎@ Seeee –