2014-03-24 3 views
-1

호출하려고하는 함수가이 범위에서 선언되지 않은 오류가 계속 발생합니다. 다음은 코드 블록입니다. 컴파일러는 "이 범위에서 XXX이 선언되지 않았습니다"라는 함수에 대한 오류를 반환합니다. 문제의 위치를 ​​알 수 없으므로 모든 코드를 포함 시켰습니다. 죄송합니다. 그리고 이것에 대한 도움을 주셔서 감사합니다.이 범위에서 선언되지 않은 함수

다음은 제대로 작동하지 않는 작은 예입니다.

void kitchenOption(void); 
int main() 
{ 
kitchenOption(); 
} 
/****************************** 
* Function Name: kitchenOption 
* Return Type: none 
* Parameters: none 
* Description: Gives the Kitchen Options and updates the global variable. 
* ****************************/ 
void kitchenOption(void) 
{ 
    std::cout << "You may add deluxe wooden cabinets and granite cabinets for an additional $20,000." << std::endl; 
    std::cout << "If you would like deluxe cabinets and countertops, please input 1." << std::endl; 
    std::cout << "If you do not want deluxe cabinets and countertops, please input 2." << std::endl; 
    std::cin >> kitchenChoice; 

    if(kitchenChoice == 1) 
    { 
      std::cout << "You have selected deluxe cabinets and contertops. This adds $20,000 to your Optional Features Cost." << std::endl; 
      optionalFeaturesCost += 20000; 
      std::cout << "Your Optional Features Cost is now $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
    } 
    else if(kitchenChoice == 2) 
    { 
      std::cout << "You have selected to not have deluxe caibnets and countertops." << std::endl; 
    } 
    else 
    { 
      std::cout << "That is not a valid input." << std::endl; 
      exit(1); 
    } 
} 

이^기능은 제대로 작동하지 않는 예입니다. 코드의 나머지 부분은 다음과 같습니다.

#include<iostream> 
using std::cout; 
using std::endl; 
using std::fixed; 

#include<iomanip> 
using std::setprecision; 

#include <stdlib.h> 

//Fixed Variable Declarations and Assignments 
float STATE_TAX_RATE = .075; 
float PERCENT_PROFIT = .25; 
float COST_PER_SQUARE_FT = 66.67; 

//Variable declarations and Initial Assignments 
double houseSquareFootage = 0.0; 
double basicHomeCost = 0.0; 
double profit = 0.0; 
double netHomeCost = 0.0; 
double taxes = 0.0; 
double totalHomeCost = 0.0; 
double optionalFeaturesCost = 0.0; 
double discount = 0.0; 
int houseChoice = 0; 
int bedroomChoice = 0; 
int kitchenChoice = 0; 
int interiorChoice = 0; 
int loopVar = 1; 
int loopChoice = 0; 

//Function Declarations 
int houseOption(void); 
void welcomeMessage(void); 
void bedroomOption(void) 
void kitchenOption(void); 
void designOption(void); 
void displayDiscount(void); 
void displaySummary(void); 
void dmoreQuoteOption(void); 
void thankYouMessage(void); 

int main() 
{ 
do{ 
//reset Variables 
houseChoice = 0; 
bedroomChoice = 0; 
kitchenChoice = 0; 
interiorChoice = 0; 
optionalFeaturesCost = 0; 
discount = 0; 

//Welcome Message 
welcomeMessage(); 

//House Option 
houseChoice = houseOption(); 

if(houseChoice == 1) 
{ 
     std::cout << "You have selected the standard house." << std::endl; 
     houseSquareFootage = 3000; 
     displaySummary(); 
     moreQuoteOption(); 
} 
else if (houseChoice == 2) 
{ 

std::cout << "You have selected a custom house." << std::endl; 

//Bedroom Option 
bedroomOption(); 

//Kitchen Option 
kitchenOption(); 

//Design Option 
designOption(); 

//Discount 
displayDiscount(); 

//Run Calculations and Report 
displaySummary(); 
} 

else 
{ 
     std::cout << "That is not a valid input" << std::endl; 
     exit(1); 
} 
} while (loopVar <= 5); 
} 

/************************************* 
* Function Type: welcomeMessage 
* Return Type: none 
* parameters: none 
* Description: Welcomes the user to the house pogram 
* **********************************/ 
void welcomeMessage(void) 
{ 
     std::cout << "Weloome to the House Selection Program." << std::endl; 
     std::cout << "This program will allow you to select features for" << std::endl; 
     std::cout << " and calculate costs for up to 5 houses." << std::endl; 
} 

/************************************* 
* Function Name: houseOption 
* Return Type: Int 
* Parameters: none 
* Description: Gives the house options and returns an int to save the info. 
***********************************/
int houseOption(void) 
{ 
     std::cout << "Would you like a standard house or a custom house?" << std::endl; 
     std::cout << "Input 1 for a standard house or 2 for a custom house." << std::endl; 
     std::cin >> houseChoice; 
     return houseChoice; 
} 

/********************************* 
* Function Name: bedroomOption 
* Return Type: none 
* Parameters: none 
* Description: Gives the bedroom options and updates the globabl variable. 
* *****************************/ 
void bedroomOption(void) 
{ 
     std::cout << "You may add 1 or 2 extra bedrooms. Each bedroom will add 360 sq ft to the house." << std::endl; 
     std::cout << "Enter 0 for no extra bedrooms, 1 for one extra bedroom, or 2 for two extra bedrooms." << std::endl; 
     std::cin >> bedroomChoice; 

     if(bedroomChoice == 0) 
     { 
       std::cout << "You have chosen to not have any extra bedrooms. The Square Footage of the house is 3000." << std::endl; 
       houseSquareFootage = 3000; 
       return houseSquareFootage; 
     } 
     else if(bedroomChoice == 1) 
     { 
       std::cout << "You have chosen to add one extra bedroom. The Square Footage of the house is 3360." << std::endl; 
       houseSquareFootage = 3360; 
       return houseSquareFootage; 
     } 
     else if(bedroomChoice == 2) 
     { 
       std::cout << "You have chosen to add two extra bedrooms. The Square Footage of the house is 3720." << std::endl; 
       houseSquareFootage = 3720; 
       return houseSquareFootage; 
     } 
     else 
     { 
       std::cout << "That is not a valid input." << std::endl; 
       exit(1); 
     } 


} 

/****************************** 
* Function Name: kitchenOption 
* Return Type: none 
* Parameters: none 
* Description: Gives the Kitchen Options and updates the global variable. 
* ****************************/ 
void kitchenOption(void) 
{ 
     std::cout << "You may add deluxe wooden cabinets and granite cabinets for an additional $20,000." << std::endl; 
     std::cout << "If you would like deluxe cabinets and countertops, please input 1." << std::endl; 
     std::cout << "If you do not want deluxe cabinets and countertops, please input 2." << std::endl; 
     std::cin >> kitchenChoice; 

     if(kitchenChoice == 1) 
     { 
       std::cout << "You have selected deluxe cabinets and contertops. This adds $20,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 20000; 
       std::cout << "Your Optional Features Cost is now $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(kitchenChoice == 2) 
     { 
       std::cout << "You have selected to not have deluxe caibnets and countertops." << std::endl; 
     } 
     else 
     { 
       std::cout << "That is not a valid input." << std::endl; 
       exit(1); 
     } 
} 

/*************************** 
* Function Name: designOption 
* Return Type: none 
* Parameters: none 
* Description: Gives the Design options and updates the global variable. 
* *************************/ 
void designOption(void) 
{ 
     std::cout << "There are four interior options and are as follows..." << std::endl; 
     std::cout << "Option 1: Hardwood floors for the den, kitchen, and family room. Cost: $10,000" << std::endl; 
     std::cout << "Option 2: All of Option 1 as well as solid brass lighting fixtures in and out. Cost: $20,000" << std::endl; 
     std::cout << "Option 3: All of Option 2 as well as plush carpeting, ceramic tile, and real wood paneling. Cost: $25,000" << std::endl; 
     std::cout << "Option 4: All of Option 3 as well as gold kitchen and bath fixtures, Jacuzzi and Sauna. Cost: $30,000" << std::endl; 
     std::cout << "----" << std::endl; 
     std::cout << "Please input 0 for no extra interior features, 1 for Option 1, 2 for Option 2, 3 for Option 3, or 4 for Option 4." << std::endl; 
     std::cin >> interiorChoice; 

     if(interiorChoice == 0) 
     { 
       std::cout << "You have chosen to not have any extra interior features." << std::endl; 
     } 
     else if(interiorChoice == 1) 
     { 
       std::cout << "You have selected Option 1. This adds $10,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 10000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 2) 
     { 
       std::cout << "You have selected Option 2. This adds $20,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 20000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 3) 
     { 
       std::cout << "You have selected Option 3. This adds $25,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 25000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 4) 
     { 
       std::cout << "You have selected Option 4. This adds $30,000 to your Optional Features Cost." << std::endl; 
       option alFeaturesCost += 30000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else 
     { 
       std::cout << "That is not a valid input." << std::endl; 
       exit(1); 
     } 
} 

/************************* 
* Function Name: displayDiscount 
* Return Type: none 
* Parameters: none 
* Description: Checks for discount and displays it. This function also performs the role of calculateDiscount(). 
* ************************/ 
void displayDiscount(void) 
{ 
     std::cout << "If the optional features cost exceeds $30,000, a 10% discount on the optional features will be awarded." << std::endl; 

     if(optionalFeaturesCost >= 30000) 
     { 
       discount = optionalFeaturesCost*0.1; 
       std::cout << "An Optional Features Cost of $" << setprecision(2) << fixed << optionalFeaturesCost << 
       " exceeds the requirement of $30,000, and thus a 10% discount of $" << setprecision(2) << fixed << discount 
       << " has been awarded." << std::endl; 
     } 
     else 
     { 
         std::cout << "An Optional Features Cost of $" << setprecision(2) << fixed << optionalFeaturesCost << 
       " does not meet the requirement of $30,000, and thus, no discount is awarded." << std::endl; 
     } 
} 

/*********************** 
* Function Name: displaySummary 
* Return type: none 
* Parameters: none 
* Description: Displays all relevant info as a summary. This function also performs the role of calculateFinalCost(). 
* *******************/ 
void displaySummary(void) 
{ 
     //Calculating Basic Home Cost 
     basicHomeCost = houseSquareFootage * COST_PER_SQUARE_FT; 

     //Calculating Profit 
     profit = (basicHomeCost + optionalFeaturesCost) * PERCENT_PROFIT; 

     //Calculating Net Home Cost 
     netHomeCost = basicHomeCost + optionalFeaturesCost + profit - discount; 

     //Calculating Taxes 
     taxes = netHomeCost * STATE_TAX_RATE; 

     //Calculating totalHomeCost 
     totalHomeCost = netHomeCost + taxes; 

     //Reporting Information 
     std::cout << "House Square Footage: " << setprecision(2) << fixed << houseSquareFootage << std::endl; 
     std::cout << "Basic Home Cost: " << setprecision(2) << fixed << basicHomeCost << std::endl; 
     std::cout << "Optional Features Cost: " << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     std::cout << "Discount: " << setprecision(2) << fixed << discount << std::endl; 
     std::cout << "Net Home Cost: " << setprecision(2) << fixed << netHomeCost << std::endl; 
     std::cout << "Profit: " << setprecision(2) << fixed << profit << std::endl; 
     std::cout << "Taxes: " << setprecision(2) << fixed << taxes << std::endl; 
     std::cout << "Total Home Cost: " << setprecision(2) << fixed << totalHomeCost << std::endl; 
     { 
       std::cout << "You have selected deluxe cabinets and contertops. This adds $20,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 20000; 
       std::cout << "Your Optional Features Cost is now $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(kitchenChoice == 2) 
     { 
       std::cout << "You have selected to not have deluxe caibnets and countertops." << std::endl; 
     } 
     else 
     { 
       std::cout << "That is not a valid input." << std::endl; 
       exit(1); 
     } 
} 

/*************************** 
* Function Name: designOption 
* Return Type: none 
* Parameters: none 
* Description: Gives the Design options and updates the global variable. 
* *************************/ 
void designOption(void) 
{ 
     std::cout << "There are four interior options and are as follows..." << std::endl; 
     std::cout << "Option 1: Hardwood floors for the den, kitchen, and family room. Cost: $10,000" << std::endl; 
     std::cout << "Option 2: All of Option 1 as well as solid brass lighting fixtures in and out. Cost: $20,000" << std::endl; 
     std::cout << "Option 3: All of Option 2 as well as plush carpeting, ceramic tile, and real wood paneling. Cost: $25,000" << std::endl; 
     std::cout << "Option 4: All of Option 3 as well as gold kitchen and bath fixtures, Jacuzzi and Sauna. Cost: $30,000" << std::endl; 
     std::cout << "----" << std::endl; 
     std::cout << "Please input 0 for no extra interior features, 1 for Option 1, 2 for Option 2, 3 for Option 3, or 4 for Option 4." << std::endl; 
     std::cin >> interiorChoice; 

     if(interiorChoice == 0) 
     { 
       std::cout << "You have chosen to not have any extra interior features." << std::endl; 
     } 
     else if(interiorChoice == 1) 
     { 
       std::cout << "You have selected Option 1. This adds $10,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 10000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 2) 
     { 
       std::cout << "You have selected Option 2. This adds $20,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 20000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 3) 
     { 
       std::cout << "You have selected Option 3. This adds $25,000 to your Optional Features Cost." << std::endl; 

     if(kitchenChoice == 1) 
     { 
       std::cout << "You have selected deluxe cabinets and contertops. This adds $20,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 20000; 
       std::cout << "Your Optional Features Cost is now $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(kitchenChoice == 2) 
     { 
       std::cout << "You have selected to not have deluxe caibnets and countertops." << std::endl; 
     } 
     else 
     { 
       std::cout << "That is not a valid input." << std::endl; 
       exit(1); 
     } 
} 

/*************************** 
* Function Name: designOption 
* Return Type: none 
* Parameters: none 
* Description: Gives the Design options and updates the global variable. 
* *************************/ 
void designOption(void) 
{ 
     std::cout << "There are four interior options and are as follows..." << std::endl; 
     std::cout << "Option 1: Hardwood floors for the den, kitchen, and family room. Cost: $10,000" << std::endl; 
     std::cout << "Option 2: All of Option 1 as well as solid brass lighting fixtures in and out. Cost: $20,000" << std::endl; 
     std::cout << "Option 3: All of Option 2 as well as plush carpeting, ceramic tile, and real wood paneling. Cost: $25,000" << std::endl; 
     std::cout << "Option 4: All of Option 3 as well as gold kitchen and bath fixtures, Jacuzzi and Sauna. Cost: $30,000" << std::endl; 
     std::cout << "----" << std::endl; 
     std::cout << "Please input 0 for no extra interior features, 1 for Option 1, 2 for Option 2, 3 for Option 3, or 4 for Option 4." << std::endl; 
     std::cin >> interiorChoice; 

     if(interiorChoice == 0) 
     { 
       std::cout << "You have chosen to not have any extra interior features." << std::endl; 
     } 
     else if(interiorChoice == 1) 
     { 
       std::cout << "You have selected Option 1. This adds $10,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 10000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 2) 
     { 
       std::cout << "You have selected Option 2. This adds $20,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 20000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 3) 
     { 
       std::cout << "You have selected Option 3. This adds $25,000 to your Optional Features Cost." << std::endl; 
       optionalFeaturesCost += 25000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else if(interiorChoice == 4) 
     { 
       std::cout << "You have selected Option 4. This adds $30,000 to your Optional Features Cost." << std::endl; 
       option alFeaturesCost += 30000; 
       std::cout << "Your Optional Features Cost is $" << setprecision(2) << fixed << optionalFeaturesCost << std::endl; 
     } 
     else 
     { 
       std::cout << "That is not a valid input." << std::endl; 
                                                   201,1   63% 
+0

이것은 실제로 C++이 아니며 ... 너무 길어서 걸어 갈 수없는 작은 예제를 만들고 게시합니다. – Walter

+0

* 불만을 제기하는 기능은 무엇입니까? 예제를 문제를 보여주는 최소한의 파일로 잘라주십시오. 누락 된 선언이나 다른 실수를 찾아 다니는 백 줄을 따라 가보는 것은 낯선 사람의 질문에 답하기 위해 내가 할 정도로 재미 있지 않습니다. 죄송합니다. – vonbrand

+0

왜 코드에 컴파일러 오류 메시지가 있습니까? – fritzone

답변

2

다른 사람의 원인이 될 수 있기 때문에 항상 첫 번째 오류에 집중하십시오. 이 경우

void bedroomOption(void) 

뒤에 세미 콜론이 누락되어 많은 가짜 오류가 발생하는 컴파일러를 혼동하게됩니다.

관련 문제