2014-03-24 96 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++ ...而且我们通过...做出一个* small *示例并发布它的方式太漫长了。 – Walter

+0

*它抱怨什么*功能?请将该示例截至最小文件显示该问题;通过一百多条线索寻找缺失的宣言或任何其他错误,对于我来说只是为了回答陌生人的问题而已。抱歉。 – vonbrand

+0

为什么你的代码中有编译器错误信息? – fritzone

回答

2

总是关注第一个错误,因为它可能是其他人的原因。在这种情况下,你错过了一个分号后

void bedroomOption(void) 

这是令人困惑的编译器导致大量的假错误。