2013-10-02 5 views
-4

다른 모양의 영역 및 부피를 계산하는 할당 수행. 붙어 다니는 것은 삼가면서 말하는 것입니다. 'showMenu'를 요청하는 오류를 가져옵니다. 함수는 0 인수를 취하지 않습니다. & 또한 함수 호출 오류가 너무 적습니다. 이 문제를 해결하는 방법에 대한 모든 포인터?함수 호출 오류가 너무 적음

#include <iostream> 
#include <iomanip> 
using namespace std; 

//Functions 
void showMenu(int &); 
double area (double, double); 
double area (double); 
double volume (double, double, double); 
double volume (double); 
const double PI = 3.14; 

int main() 
{ 
int choice; 
double area, volume, length, width, radius, height; 
const double PI = 3.14; 

do 
{ 
    showMenu(); 
    cin >> choice; 

    if (choice < 1 || choice > 5) 
    { 
     cout << "Please select a valid choice of 1-5: " << endl; 
     cin >> choice; 
    } 
    else if (choice == 1) 
    { 

     double tarea(area); 
     cout << "Enter the length: "; 
     cin >> length; 
     cout << "Enter the width: "; 
     cin >> width; 
     cout << "The area of the rectangle is: " << tarea << endl; 

    } 
    else if (choice == 2) 
    { 

     double tarea(area); 
     cout << "Enter the radius: "; 
     cin >> radius; 
     cout << "The area of the circle is: " << tarea << endl; 

    } 
    else if (choice == 3) 
    { 

     double tvolume (volume); 
     cout << "Enter the length: "; 
     cin >> length; 
     cout << "Enter the width: "; 
     cin >> width; 
     cout << "Enter the height: "; 
     cin >> height; 
     cout << "The volume for a box is: " << tvolume << endl; 

    } 
    else if (choice == 4) 
    { 

     double tvolume (volume); 
     cout << "Enter the radius: "; 
     cin >> radius; 
     cout << "The volume of a sphere is: " << endl; 

    } 
} 
    while (choice != 5); 
return 0; 
} 

void ShowMenu(int &choice) 
{ 
    cout << "1. Calculate the area of a rectangle"; 
    cout << "2. Calculate the area of a circle"; 
    cout << "3. Calculate the volume for a box"; 
    cout << "4. Calculate the volume of a sphere"; 
    cout << "5. Quit"; 

} 

double area (double length, double width) 
{ 
    double tarea = length * width; 
    return tarea; 
} 

double area (double radius) 
{ 
    double tarea = PI * (radius * radius); 
    return tarea; 
} 

double volume (double length, double width, double height) 
{ 

    double tvolume = length * width * height; 
    return tvolume; 
} 

double volume (double radius) 
{ 
    double tvolume = (4/3) * PI * (radius * radius * radius); 
    return tvolume; 
} 
+2

매개 변수를 사용하거나 사용하지 않으므로 매개 변수를 꺼내시겠습니까? – chris

답변

3

매우 간단 :

showMenu(int&); 

는 하나 개의 인자를받는 함수의 ShowMenu는을 선언합니다.

당신은 전화 :

showMenu(); 

은 따라서 당신이 어떤 값을 전달해야합니다

int i = some_value; 
showMenu(i); 

또는 인수를 ShowMenu는 없습니다 :

void showMenu() { 
    //all those couts 
} 
0

C++는 경우입니다 sensetive. 선언하고 showMenu를 호출하지만 ShowMenu를 정의합니다. 또한 showMenu의 정의에는 인수가 있지만 인수없이 호출합니다. 다시 확인해보십시오. 이 컴파일러 알려줍니다

void showMenu(int &); 

:

10

는이 기능 delcaration 있습니다.

OK, 어딘가 showMenu` "라는 함수가를이 아무 것도 반환하지 않으며, 하나의 매개 변수를 또는 reference-to-int를 입력하십시오. "

그런 다음 당신은 함수를 호출하려고 :

전화 기능 "ShowMenu는"

showMenu(); 

이 컴파일러를 알려줍니다. 나는 그것이 무엇을 반환하는지 상관하지 않으며, 나는 showMenu에게 아무 것도 전달하지 않고 입니다.

컴파일러는 불평 :

이봐, 친구. "showMenu"는 reference-to-int 유형의 매개 변수 중 하나를 취한 다음 매개 변수없이 호출하려고했습니다. 무엇을 제공합니까?

컴파일러는 정직하게 유지합니다.

관련 문제