Thread: Functions, have errors...NEED HELP FAST

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Functions, have errors...NEED HELP FAST

    This is my program

    #include <iostream>
    #include <iomanip>
    #include "apstring.h"

    using namespace std;

    void ExplainProgram();
    int getInteger(const apstring &prompt);
    double getDouble(const apstring &prompt);
    void DisplayAdults(int adults);
    void DisplayChild(int children);
    void DisplayAmeal(double adultMeal);
    void DisplayCmeal(double childMeal);
    void DisplayDmeal(double dessertMeal);
    void DisplayRoom(double roomCost);
    void DisplayTrate(double tiptaxRate);
    void DisplayCadults(double adultCost);
    void DisplayChild(double childCost);
    void DisplayDessert(double dessertCost);
    void DisplayFood(double foodCost);
    void DisplayTiptax(double tiptaxCost);
    void DisplayRoom(double roomCost);
    void DisplayDeposit(double depositCost);
    void DisplayCost(double foodCost, double tiptaxCost, double roomCost, double depositCost);
    double CalculateAdultCost(int adults, double adultMeal);
    double CalculateChildCost(int children, double childMeal);
    double CalculateDessertCost(int adults, int children, double dessertMeal);
    double CalculateFoodCost(double adultCost, double childCost, double desserCost);
    double CalculateTiptaxCost(double foodCost, double tiptaxRate);
    double CalculateTotalCost(double foodCost, double tiptaxCost, double roomCost, double depositCost);

    int main()
    {
    int adults; // number of adult meals
    int children; // number of children meals
    double adultMeal; // cost per adult meal
    double childMeal; // cost per child meal
    double dessertMeal; // cost per dessert meal
    double roomCost; // cost of the room fee
    double tiptaxRate; // tip and tax rate
    double adultCost; // cost of all adult meals bought
    double childCost; // cost of all child meals bought
    double dessertCost; // cost of all the desserts bought
    double foodCost; // sot of all food meals bought
    double tiptaxCost; // cost of all the tax and tips
    double totalCost; // cost of all meals bought

    ExplainProgram(); // Explain the program to the user
    adults = getInteger("Number of adults: ");
    children = getInteger("Number of children: ");
    adultMeal = getDouble("Enter cost per adult without dessert: ");
    childMeal = getDouble("Enter cost per child without dessert: ");
    dessertMeal = getDouble("Enter cost per dessert: ");
    roomCost = getDouble("Enter room fee: ");
    tiptaxRate = getDouble("Enter tip and tax rate: ");
    adultCost = CalculateAdultCost(adults); // Calculate total adult meal cost
    childCost = CalculateChildCost(children); // Calculate total child meal cost
    dessertCost = CalculateDessertCost(adults,children,dessertMeal); // Calculate total dessert cost
    foodCost = CalculateFoodCost(adultCost,childCost,dessertCost) ; // Calculate total food cost
    tiptaxCost = CalculateTiptaxCost(tiptaxRate,tiptaxCost); // Calculate total tips and tax cost
    totalCost = CalculateTotalCost(foodCost,tiptaxCost,roomCost,de positCost); // Calculate total the total balance due
    DisplayAdults(adults); // Display number of adults
    DisplayChild(children); // Display number of children
    DisplayAmeal(adultMeal); // Display cost per adult meal
    DisplayCmeal(childMeal); // Display cost per child meal
    DisplayDmeal(dessertMeal); // Display cost per dessert meal
    DisplayRoom(roomCost); // Display the room fee
    DisplayTrate(tiptaxRate); // Display tip and tax rate
    DisplayCadults(adultCost); // Display the total adult cost
    DisplayChild(childCost); // Display the total child cost
    DisplayDessert(dessertCost); // Display the total dessert cost
    DisplayFood(foodCost); // Display the total food cost
    DisplayTiptax(tiptaxCost); // Display the total tip and tax cost
    DisplayRoom(roomCost); // Display the room fee
    DisplayDeposit(depositCost); // Display the deposit amount
    DisplayCost(foodCost,tiptaxCost,roomCost,depositCo st); // Display the balance due

    system("PAUSE");
    return 0;
    }

    int getInteger(const apstring &prompt)
    {
    int number;
    cout << prompt;
    cin >> number;

    return number;
    }

    double getDouble(const apstring &prompt)
    {
    double number;
    cout << prompt;
    cin >> number;

    return number;
    }

    // Function: CalculateTotalCost
    // Input: 2 parameters of type double which represent the cost of the adult and child
    // meals
    // Output: the total cost is returned as a double value
    // Task: to calculate the total cost of the meals purchased
    double CalculateTotalCost(double foodCost, double tiptaxCost, double roomCost, double depositCost)
    {
    double cost; // total balance due

    cost = foodCost + tiptaxCost + roomCost - depositCost;

    return cost;
    }

    // Function: CalculateFoodCost
    // Input: 3 parameters of type double which represent the cost of the adult, child
    // and dessert meals
    // Output: the food cost is returned as a double value
    // Task: to calculate the total cost of the food meals purchased
    double CalculateFoodCost(double adultCost, double childCost, double dessertCost)
    {
    double cost; // total cost for all meals purchased

    cost = adultCost + childCost + dessertCost;

    return cost;
    }

    // Function: ExplainProgram
    // Input: Nothing
    // Output: Nothing is returned but an explanation is placed on the output screen
    // Task: Display an explanation of the program on the screen to inform
    // the user of the program's purpose
    void ExplainProgram()
    {
    cout << "This program will determine the cost of an adult and childs\n"
    << "meal, dessert cost, room cost, tip and tax cost and total cost.\n"
    << "User will enter the number of adult and children and the program will\n"
    << "determine the cost of the meals, dessert, room, tip, tax and total.\n\n";
    }

    // Function: DisplayCost
    // Input: 8 parameters of type double representing the adult cost, child cost, dessert cost,
    // food cost, tip/tax cost, room cost, deposit cost and total cost are received
    // Output: Nothing is returned but an invoice of costs is displayed on
    // the output screen
    // Task: Display cost information on the screen for the user
    void DisplayCost(int adults, int children, double adultMeal, double childMeal, double adultCost,
    double childCost, double dessertCost, double foodCost, double tiptaxRate, double tiptaxCost, double roomCost,
    double depositCost, double totalCost)
    {
    cout << endl;
    cout << "Causewell Catering and Convention Service" << endl;
    cout << "Final Bill" << endl;
    cout << endl;
    cout << setiosflags(ios::fixed) << setprecision(2);
    cout << "Number of adults: " << adults << endl;
    cout << "Number of children: " << children << endl;
    cout << "Cost per adult without dessert: " << setw(6) << adultMeal << endl;
    cout << "Cost per child without dessert: " << setw(6) << childMeal << endl;
    cout << "Room fee: " << setw(6) << roomCost << endl;
    cout << "Tip and tax rate: " << setw(6) << tiptaxRate << endl;
    cout << endl;
    cout << "Total Cost for adult meals: $" << setw(6) << adultCost << endl;
    cout << "Total cost for child meals: $" << setw(6) << childCost << endl;
    cout << "Total cost for dessert: $" << setw(6) << dessertCost << endl;
    cout << "Total food cost: $" << setw(6) << foodCost << endl;
    cout << "Plus tip and tax: $" << setw(6) << tiptaxCost << endl;
    cout << "Plus room fee: $" << setw(6) << roomCost << endl;
    cout << "Less deposit: $" << setw(6) << depositCost << endl;
    cout << endl;
    cout << "Balance due: $" << setw(6) << totalCost << endl;
    }

    // Function: CalculateAdultCost
    // Input: Receives 1 parameter which represents the number of adult meals
    // and it accesses 1 global constant (adultMeal) which represents the
    // cost of one adult meal
    // Output: return a double which represents the cost for all adult meals
    // purchased
    // Task: Calculate the cost of all of the adult tickets being purchased
    double CalculateAdultCost(int adults, double adultMeal)
    {
    double cost; // cost of adult meals purchased

    cost = adults * adultMeal;

    return cost;
    }

    // Function: CalculateChildCost
    // Input: Receives 1 parameter which represents the number of child meals
    // and it accesses 1 global constant (childMeal) which represents the
    // cost of one child meal
    // Output: return a double which represents the cost for all child meals
    // purchased
    // Task: Calculate the cost of all of the child meals being purchased
    double CalculateChildCost(int children, double childMeal)
    {
    double cost; // cost of child meals purchased

    cost = children * childMeal;

    return cost;
    }

    // Function: CalculateDessertCost
    // Input: Receives 1 parameter which represents the number of child meals
    // and it accesses 1 global constant (dessertMeal) which represents the
    // cost of one dessert meal
    // Output: return a double which represents the cost for all dessert meals
    // purchased
    // Task: Calculate the cost of all of the dessert meals being purchased
    double CalculateDesertCost(double dessertMeal, int adults, int children)
    {
    double cost; // cost of dessert meals purchased

    cost = dessertMeal * (adults + children);

    return cost;
    }

    // Function: CalculateTiptaxCost
    // Input: Receives 1 parameter which represents the number of child meals
    // and it accesses 1 global constant (tiptaxRate) which represents the
    // rate of tips and tax
    // Output: return a double which represents the amount of total tips and
    // tax
    // Task: Calculate the total cost of tips and tax
    double CalculateTiptaxCost(double tiptaxRate, double foodCost)
    {
    double cost; // tip and tax rate

    cost = tiptaxRate * foodCost;

    return cost;
    }

    Im getting these errors(there is more errors i know)

    \CS170B-Catering-afinstad\Catering.cpp U:\CS170B-Catering-afinstad\U apstring.h: No such file or directory.

    18 U:\CS170B-Catering-afinstad\Catering.cpp expected `,' or `...' before '&' token

    18 U:\CS170B-Catering-afinstad\Catering.cpp ISO C++ forbids declaration of `apstring' with no type

    19 U:\CS170B-Catering-afinstad\Catering.cpp expected `,' or `...' before '&' toke

    19 U:\CS170B-Catering-afinstad\Catering.cpp ISO C++ forbids declaration of `apstring' with no type

    U:\CS170B-Catering-afinstad\Catering.cpp In function `int main()':

    59 U:\CS170B-Catering-afinstad\Catering.cpp invalid conversion from `const char*' to `int'

    59 U:\CS170B-Catering-afinstad\Catering.cpp initializing argument 1 of `int getInteger(int)'

    35 U:\CS170B-Catering-afinstad\Catering.cpp too few arguments to function `double CalculateAdultCost(int, double)'

    66 U:\CS170B-Catering-afinstad\Catering.cpp at this point in file

    71 U:\CS170B-Catering-afinstad\Catering.cpp `depositCost' undeclared (first use this function)

    93 U:\CS170B-Catering-afinstad\Catering.cpp ISO C++ forbids declaration of `apstring' with no type

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Wow, you're an ass, huh? Let's just dump a bunch of unformatted code on a forum.

    I don't care how URGENT you think your request for help is...have some damn manners and read the new users post, then fix this abomination of a post.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    Code:
    #include <iostream>
    #include <iomanip>
    #include "apstring.h"
    
    using namespace std;
    
    void ExplainProgram();
    int getInteger(const apstring &prompt);
    double getDouble(const apstring &prompt);
    void DisplayAdults(int adults);                                                  
    void DisplayChild(int children);                                                  
    void DisplayAmeal(double adultMeal);                                                
    void DisplayCmeal(double childMeal);                                          
    void DisplayDmeal(double dessertMeal);                                            
    void DisplayRoom(double roomCost);                                                 
    void DisplayTrate(double tiptaxRate);                                                
    void DisplayCadults(double adultCost);                                                
    void DisplayChild(double childCost);                                                  
    void DisplayDessert(double dessertCost);                                             
    void DisplayFood(double foodCost);                                                    
    void DisplayTiptax(double tiptaxCost);                                                
    void DisplayRoom(double roomCost);                                                    
    void DisplayDeposit(double depositCost);                                              
    void DisplayCost(double foodCost, double tiptaxCost, double roomCost, double depositCost);
    double CalculateAdultCost(int adults, double adultMeal);
    double CalculateChildCost(int children, double childMeal);
    double CalculateDessertCost(int adults, int children, double dessertMeal);
    double CalculateFoodCost(double adultCost, double childCost, double desserCost);
    double CalculateTiptaxCost(double foodCost, double tiptaxRate);
    double CalculateTotalCost(double foodCost, double tiptaxCost, double roomCost, double depositCost);
    
    int main()
    {
    	int adults;			// number of adult meals
    	int children;		// number of children meals
    	double adultMeal;   // cost per adult meal
    	double childMeal;   // cost per child meal
    	double dessertMeal; // cost per dessert meal
    	double roomCost;    // cost of the room fee
    	double tiptaxRate;  // tip and tax rate
    	double adultCost;	// cost of all adult meals bought
    	double childCost;	// cost of all child meals bought
    	double dessertCost; // cost of all the desserts bought
    	double foodCost;    // sot of all food meals bought
    	double tiptaxCost;  // cost of all the tax and tips
    	double totalCost;	// cost of all meals bought
    	
    	ExplainProgram();			                                              // Explain the program to the user
    	adults = getInteger("Number of adults: ");
    	children = getInteger("Number of children: ");
    	adultMeal = getDouble("Enter cost per adult without dessert: ");
    	childMeal = getDouble("Enter cost per child without dessert: ");
    	dessertMeal = getDouble("Enter cost per dessert: ");
    	roomCost = getDouble("Enter room fee: ");
        tiptaxRate = getDouble("Enter tip and tax rate: "); 
    	adultCost = CalculateAdultCost(adults);					                  // Calculate total adult meal cost
    	childCost = CalculateChildCost(children);				                  // Calculate total child meal cost
    	dessertCost = CalculateDessertCost(adults,children,dessertMeal);          // Calculate total dessert cost
    	foodCost = CalculateFoodCost(adultCost,childCost,dessertCost);            // Calculate total food cost
    	tiptaxCost = CalculateTiptaxCost(tiptaxRate,tiptaxCost);                  // Calculate total tips and tax cost
    	totalCost = CalculateTotalCost(foodCost,tiptaxCost,roomCost,depositCost); // Calculate total the total balance due
    	DisplayAdults(adults);                                                    // Display number of adults
    	DisplayChild(children);                                                   // Display number of children
    	DisplayAmeal(adultMeal);                                                  // Display cost per adult meal
    	DisplayCmeal(childMeal);                                                  // Display cost per child meal
    	DisplayDmeal(dessertMeal);                                                // Display cost per dessert meal
    	DisplayRoom(roomCost);                                                    // Display the room fee
    	DisplayTrate(tiptaxRate);                                                 // Display tip and tax rate
    	DisplayCadults(adultCost);                                                // Display the total adult cost
    	DisplayChild(childCost);                                                  // Display the total child cost
    	DisplayDessert(dessertCost);                                              // Display the total dessert cost
    	DisplayFood(foodCost);                                                    // Display the total food cost
    	DisplayTiptax(tiptaxCost);                                                // Display the total tip and tax cost
    	DisplayRoom(roomCost);                                                    // Display the room fee
    	DisplayDeposit(depositCost);                                              // Display the deposit amount
    	DisplayCost(foodCost,tiptaxCost,roomCost,depositCost);		              // Display the balance due
    
    	system("PAUSE");
        return 0;
    }
    
    int getInteger(const apstring &prompt)
    {
        int number;
        cout << prompt;
        cin >> number;
        
        return number;
    }
    
    double getDouble(const apstring &prompt)
    {
        double number;
        cout << prompt;
        cin >> number;
        
        return number;
    }
     
    // Function: CalculateTotalCost
    // Input: 2 parameters of type double which represent the cost of the adult and child
    //        meals
    // Output: the total cost is returned as a double value
    // Task: to calculate the total cost of the meals purchased
    double CalculateTotalCost(double foodCost, double tiptaxCost, double roomCost, double depositCost)
    {
    	double cost;		// total balance due
    
    	cost = foodCost + tiptaxCost + roomCost - depositCost;
    
    	return cost;
    }
    
    // Function: CalculateFoodCost
    // Input: 3 parameters of type double which represent the cost of the adult, child
    //        and dessert meals
    // Output: the food cost is returned as a double value
    // Task: to calculate the total cost of the food meals purchased
    double CalculateFoodCost(double adultCost, double childCost, double dessertCost)
    {
    	double cost;		// total cost for all meals purchased
    
    	cost = adultCost + childCost + dessertCost;
    
    	return cost;
    }
    
    // Function: ExplainProgram
    // Input: Nothing
    // Output: Nothing is returned but an explanation is placed on the output screen
    // Task: Display an explanation of the program on the screen to inform
    //       the user of the program's purpose
    void ExplainProgram()
    {
    	cout << "This program will determine the cost of an adult and childs\n"
    		 << "meal, dessert cost, room cost, tip and tax cost and total cost.\n"
    		 << "User will enter the number of adult and children and the program will\n"
    		 << "determine the cost of the meals, dessert, room, tip, tax and total.\n\n";
    }
    
    // Function: DisplayCost
    // Input: 8 parameters of type double representing the adult cost, child cost, dessert cost,
    //        food cost, tip/tax cost, room cost, deposit cost and total cost are received     
    // Output: Nothing is returned but an invoice of costs is displayed on
    //         the output screen
    // Task: Display cost information on the screen for the user
    void DisplayCost(int adults, int children, double adultMeal, double childMeal, double adultCost, 
    double childCost, double dessertCost, double foodCost, double tiptaxRate, double tiptaxCost, double roomCost, 
    double depositCost, double totalCost)
    {
    	cout << endl;
    	cout <<      "Causewell Catering and Convention Service" << endl;
    	cout <<                     "Final Bill" << endl;
    	cout << endl;
    	cout << setiosflags(ios::fixed) << setprecision(2);
    	cout << "Number of adults: " << adults << endl;
    	cout << "Number of children: " << children << endl;
    	cout << "Cost per adult without dessert: " << setw(6) << adultMeal << endl;
    	cout << "Cost per child without dessert: " << setw(6) << childMeal << endl;
    	cout << "Room fee: " << setw(6) << roomCost << endl;
    	cout << "Tip and tax rate: " << setw(6) << tiptaxRate << endl;
    	cout << endl;
    	cout << "Total Cost for adult meals: $" << setw(6) << adultCost << endl;
    	cout << "Total cost for child meals: $" << setw(6) << childCost << endl;
    	cout << "Total cost for dessert: $" << setw(6) << dessertCost << endl;
    	cout << "Total food cost: $" << setw(6) << foodCost << endl;
    	cout << "Plus tip and tax: $" << setw(6) << tiptaxCost << endl;
    	cout << "Plus room fee: $" << setw(6) << roomCost << endl;
    	cout << "Less deposit: $" << setw(6) << depositCost << endl;
    	cout << endl;
    	cout << "Balance due: $" << setw(6) << totalCost << endl;
    }
    
    // Function: CalculateAdultCost
    // Input: Receives 1 parameter which represents the number of adult meals
    //        and it accesses 1 global constant (adultMeal) which represents the
    //        cost of one adult meal
    // Output: return a double which represents the cost for all adult meals
    //         purchased
    // Task: Calculate the cost of all of the adult tickets being purchased
    double CalculateAdultCost(int adults, double adultMeal)
    {
    	double cost;	// cost of adult meals purchased
    
    	cost = adults * adultMeal; 
    
    	return cost;
    }
    
    // Function: CalculateChildCost
    // Input: Receives 1 parameter which represents the number of child meals
    //        and it accesses 1 global constant (childMeal) which represents the
    //        cost of one child meal
    // Output: return a double which represents the cost for all child meals
    //         purchased
    // Task: Calculate the cost of all of the child meals being purchased
    double CalculateChildCost(int children, double childMeal)
    {
    	double cost;	// cost of child meals purchased
    
    	cost = children * childMeal; 
    
    	return cost;
    }
    
    // Function: CalculateDessertCost
    // Input: Receives 1 parameter which represents the number of child meals
    //        and it accesses 1 global constant (dessertMeal) which represents the
    //        cost of one dessert meal
    // Output: return a double which represents the cost for all dessert meals
    //         purchased
    // Task: Calculate the cost of all of the dessert meals being purchased
    double CalculateDesertCost(double dessertMeal, int adults, int children)
    {
    	double cost;	// cost of dessert meals purchased
    
    	cost = dessertMeal * (adults + children); 
    
    	return cost;
    }
    
    // Function: CalculateTiptaxCost
    // Input: Receives 1 parameter which represents the number of child meals
    //        and it accesses 1 global constant (tiptaxRate) which represents the
    //        rate of tips and tax
    // Output: return a double which represents the amount of total tips and
    //         tax
    // Task: Calculate the total cost of tips and tax
    double CalculateTiptaxCost(double tiptaxRate, double foodCost)
    {
    	double cost;	// tip and tax rate
    
    	cost = tiptaxRate * foodCost; 
    
    	return cost;
    }

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Apparently, apstring.h doesn't exist. So fix that first, that should fix most of your errors.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    Im sure i need apstring in there somewhere

    Complete list of errors are:

    13:22: apstring.h: No such file or directory
    18: error: expected `,' or `...' before '&' token
    18: error: ISO C++ forbids declaration of `apstring' with no type
    19: error: expected `,' or `...' before '&' token
    19: error: ISO C++ forbids declaration of `apstring' with no type

    In function `int main()':
    59: error: invalid conversion from `const char*' to `int'
    59: error: initializing argument 1 of `int getInteger(int)'
    60: error: invalid conversion from `const char*' to `int'
    60: error: initializing argument 1 of `int getInteger(int)'
    61: error: invalid conversion from `const char*' to `int'
    61: error: initializing argument 1 of `double getDouble(int)'
    62: error: invalid conversion from `const char*' to `int'
    62: error: initializing argument 1 of `double getDouble(int)'
    63: error: invalid conversion from `const char*' to `int'
    63: error: initializing argument 1 of `double getDouble(int)'
    64: error: invalid conversion from `const char*' to `int'
    64: error: initializing argument 1 of `double getDouble(int)'
    65: error: invalid conversion from `const char*' to `int'
    65: error: initializing argument 1 of `double getDouble(int)'
    35: error: too few arguments to function `double CalculateAdultCost(int, double)'
    66: error: at this point in file
    36: error: too few arguments to function `double CalculateChildCost(int, double)'
    67: error: at this point in file
    71: error: `depositCost' undeclared (first use this function)
    71: error: (Each undeclared identifier is reported only once for each function it appears in.)
    At global scope:
    92: error: expected `,' or `...' before '&' token
    93: error: ISO C++ forbids declaration of `apstring' with no type
    In function `int getInteger(int)':
    95: error: `prompt' undeclared (first use this function)
    At global scope:
    101: error: expected `,' or `...' before '&' token
    102: error: ISO C++ forbids declaration of `apstring' with no type
    In function `double getDouble(int)':
    104: error: `prompt' undeclared (first use this function)

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by alkamenes View Post
    Im sure i need apstring in there somewhere
    Yes, you do. So fix it so it is included. How obviously does "No such file or directory" have to be for you to understand?

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Forget apstring header, that is no longer used, try 'homeworkcompletion.h' or nowayidontbelieveyouman.h' instead, should get job done

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. HELP with DX9 Errors!!!
    By Tommaso in forum Game Programming
    Replies: 7
    Last Post: 06-28-2006, 02:51 PM
  3. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  4. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM
  5. Variables do not equal functions!!!
    By me@burk. in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 06:24 AM