2017-03-09 87 views
-2

我想從最大打印第三位最低爲3個數字,當我嘗試編譯這段代碼就說明我這個錯誤C2065 "function parameter :Undeclared identifier function parameter"爲每個函數的參數。其他錯誤是C 2062 type "int" unexpected。 這裏是我的代碼未說明的標識符++

#include "stdafx.h" 
#include <iostream> 

using namespace std; 

int max, min;//making global variable of max and min 

void numMax(int x, int y, int z);//finding maximum number 
void numMin(int x, int y, int z);/finding minimum number 

int main() 
{ 
    int x, int y, int z; 
    int middle = 0; 

    cout << "This program will take 3 number and print them from minimum to maximum" << endl; 
    cout << "_________________" << endl; 
    cout << "Pleas enter three number" << endl; 
    cout << "num1 =";cin >> x;cout << endl << "\n"; 
    cout << "num2 =";cin >> y;cout << endl << "\n"; 
    cout << "num3 =";cin >> z;cout << endl << "\n"; 

    numMax(x, y, z); 
    numMin(x, y, z); 


    if (x<max & x>min) 
    { 
     middle = x; 
    } 
    if (y<max & y>min) 
    { 
     middle = y; 
    } 
    if (z<max & z>min) 
    { 
     middle = z; 
    } 

    cout <<"ordered numbers are : "<< min << "\t"<< middle << "\t" <<max ; 

    return 0; 
} 



void numMAx(int x, int y, int z) 
{ 
    int max; 

    max = x > y ? x : y; 
    max = z > max ? z : max; 
    cout << max; 
} 

void numMin(int x, int y, int z) 
{ 
    int min; 

    min = x < y ? x : y; 
    min = min<z ? min : z; 
    cout << min; 
} 

首先我定義我的功能,然後在主功能我已經通過參數函數的參數,然後我提到我的NumMax的值和NumMin的fuctions到EXCUTE他們的任務。最後我用if聲明來確定中間數字。我該怎麼辦 ?

+1

INT X,INT Y,INT Z者除外; => int x,y,z; – KonstantinL

+0

如果檢查所以你的帖子,你會看到你的評論包含單個正斜槓「/」,而不是雙斜線「//」。 – malat

+0

你注意到你聲明瞭void numMax(int x,int y,int z);但是實現了void numMAx(int x,int y,int z); 請注意實現中的函數名稱中的大寫字母A,而在聲明中它是numMax; –

回答

0
int  numMax (int x,int y ,int z) 
{ 
if(x>y && x>z)  
    return x;  
else if (y>x && y>z)  
    return y;  
else  
    return z;  
}  


int numMin(int x,int y ,int z) 
{ 

if(x<y && x<z) 
    return x; 
else if (y<x && y<z) 
    return y; 
else 
    return z; 
} 

void main() 
{ 
int x,y,z; 
int max,min; 
clrscr(); 

cout<<"\n Enter 3 Number: \n"; 

cout<<"1st Num: ";cin>>x; 
cout<<"2nd Num: ";cin>>y; 
cout<<"3rd Num: ";cin>>z; 
max = numMax(x,y,z); 
min = numMin(x,y,z); 
if(x<max && x>min) 
{ 
    middle=x; 
} 
else if(y<max && y>min) 
{ 
    middle=y; 
} 
else 
    middle=z; 

cout<<"Number from max to min are: \n "<<numMax(x,y,z)<<" "<<numMin(x,y,z)<<" "<<middle; 
}  

試試這個

+0

請縮進您的代碼 – Zharf