2012-04-07 45 views
-1

所以我使用Visual Studio C++。我目前的程序是這樣創建一個數組,反向...但我得到的錯誤「無效」應該在';'「之前。幫助將不勝感激。void'應該在'之前';'錯誤?

#include <iostream> 

using namespace std; 

int main() 

//this function outputs the array in reverse 
void reverse(double* a, int size) 
{ 

for(int i = size-1; i >= 0; --i)//either i=size or i=size-1 
{ 
cout << a[i] << ' '; 
} 
} 

回答

6

你錯過了一個開頭{在int main()之後。

所以,你的代碼將

int main() 
{ 
//this function outputs the array in reverse 
void reverse(double* a, int size) 

不過,也有其他錯誤。首先,你的主不會返回一個值。你的程序應該有不同的結構。它應該是

#include <iostream> 
using namespace std; 

//this function outputs the array in reverse 
void reverse(double* a, int size) 
{ 
    for(int i = size-1; i >= 0; --i)//either i=size or i=size-1 
    { 
     cout << a[i] << ' '; 
    } 
} 

int main() 
{ 
    return 0; 
} 

其中一些錯誤很容易通過格式化代碼來顯示。由於您使用的是Visual Studio,因此默認設置爲Ctrl + K和Ctrl + D.

+0

downvoter可以評論爲什麼? – josephthomas 2012-04-07 21:07:10

相關問題