2015-06-20 115 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 –