2015-10-19 26 views
-2

我收到提示:之前預期不合格的ID「{」令牌線8 我不知道爲什麼,我的程序應該做的5張實數的平均值。C++錯誤:預期不合格-ID在第8行

#include <iostream> 
#include <stdlib.h> 
#include <math.h> 
#include <iomanip> 

using namespace std; 

float void() 
{ 

    float a, b, c, d, e, M; 
    cout<<"Introduceti 5 numere de la tastatura: "<<endl; 
    cout<<"a=";cin>>a; 
    cout<<"b=";cin>>b; 
    cout<<"c=";cin>>c; 
    cout<<"d=";cin>>d; 
    cout<<"e=";cin>>e; 
    M=(a+b+c+d+e)/5; 
    cout<<"Media aritmetica a celor 5 numere este: "<<M<<endl; 

} 
+1

你的函數不返回任何值,所以也許你打算'無效浮動()':d –

+0

剛剛試了一下,同樣的錯誤 –

+0

對不起,我在開玩笑。 @cad給了你答案。你不能命名一個'void'函數,也不能'浮動'。這些是保留的關鍵字... –

回答

0
  1. 你不能說出像關鍵字(這裏void)的標識符。因此,您需要將函數的名稱更改爲其他名稱。

  2. 調整函數名稱後,你的函數應該返回一個float,但是你根本沒有返回任何東西。添加return聲明你的函數的底部或更換float在函數的原型void根本不返回任何東西。

  3. 每個符合C++程序上託管的實現需要一個main功能。從C++ 1Y標準草案N4296,§3.6.1:

    A program shall contain a global function called main , which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main function.

+0

我將'void'改爲'something' |對'WinMain @ 16'的未定義引用|是我目前的錯誤 並警告:函數中沒有return語句返回非void [-Wreturn-type] | –

+0

@MeiloaicaMariusOctavian太棒了。關於錯誤信息呢? – Downvoter

+0

錯誤消息是未定義的引用「的WinMain @ 16」 –

相關問題