Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,060 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,599 people online right now. Registration is fast and FREE... Join Now!




Will not compile. Need help

 
Reply to this topicStart new topic

Will not compile. Need help

ITChief
22 Apr, 2008 - 07:19 AM
Post #1

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions

The current sellProduct() function only allows the user two chances to enter enough money to buy the product. Rewrite this function so that it keeps prompting the user until enough money is entered. Build and compile the application with its modified code. The prob I'm having that the compiler gave me 309 error codes.

[
candyMachine Header File

#include <string>

using namespace std;

class cashRegister
{
public:
int getCurrentBalance() const;
//Function to show the current amount in the cash
//register.
//Postcondition: The value of cashOnHand is returned.

void acceptAmount(int amountIn);
//Function to receive the amount deposited by
//the customer and update the amount in the register.
//Postcondition: cashOnHand = cashOnHand + amountIn;

cashRegister(int cashIn = 500);
//Constructor
//Sets the cash in the register to a specific amount.
//Postcondition: cashOnHand = cashIn;
// If no value is specified when the
// object is declared, the default value
// assigned to cashOnHand is 500.

private:
int cashOnHand; //variable to store the cash
//in the register
};

]


[
dispenserType Header File
#include <string>
#include <iostream>
#include "cashResgister.h"

using namespace std;

class dispenserType
{
public:
int getNoOfItems() const;
//Function to show the number of items in the machine.
//Postcondition: The value of numberOfItems is returned.

int getCost() const;
//Function to show the cost of the item.
//Postcondition: The value of cost is returned.

void makeSale();
//Function to reduce the number of items by 1.
//Postcondition: numberOfItems--;

dispenserType(int setNoOfItems = 50, int setCost = 50);
//Constructor
//Sets the cost and number of items in the dispenser
//to the values specified by the user.
//Postcondition: numberOfItems = setNoOfItems;
// cost = setCost;
// If no value is specified for a
// parameter, then its default value is
// assigned to the corresponding member
// variable.

private:
int numberOfItems; //variable to store the number of
//items in the dispenser
int cost; //variable to store the cost of an item
};
]

[
#include <iostream>
#include "candyMachine.h"

using namespace std;

int cashRegister::getCurrentBalance() const
{
return cashOnHand;
}

void cashRegister::acceptAmount(int amountIn)
{
cashOnHand = cashOnHand + amountIn;
}

cashRegister::cashRegister(int cashIn)
{
if (cashIn >= 0)
cashOnHand = cashIn;
else
cashOnHand = 500;
}

int disspenserType::getNoOfItems() const
{
return numberOfItems;
}

int dispenserType::getCost() const
{
return cost;
}

int dispenserType::makeSale()
{
numberOfItems--;
}

dispenserType::dispenserType(int setNoOfItems, int setCost)
{
if (setNoOfItems >= 0)
numberOfItems = setNoOfItems;
else
numberOfItems = 50;

if (setCost >= 50;
cost = 50;
}

]

[

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

using namespace std;

void showSelection();
void sellProduct(dispenserType& product,
cashRegister& pCounter);

int main()
{
cashRegister counter;
dispenserType candy(100, 50);
dispenserType chips(100, 65);
dispenserType gum(75, 45);
dispenserType cookies(100, 85);

int choice; //variable to hold the selection

showSelection();
cin >> choice;

while (choice != 9)
{
switch (choice)
{
case 1:
sellProduct(candy, counter);
break;
case 2:
sellProduct(chips, counter);
break;
case 3:
sellProduct(gum, counter);
break;
case 4:
sellProduct(cookies, counter);
break;
default:
cout << "Invalid selection." << endl;
}//end switch

showSelection();
cin >> choice;
}//end while

return 0;
}//end main


void showSelection()
{
cout << "*** Welcome to Shelly's Candy Shop ***" << endl;
cout << "To select an item, enter " << endl;
cout << "1 for Candy" << endl;
cout << "2 for Chips" << endl;
cout << "3 for Gum" << endl;
cout << "4 for Cookies" << endl;
cout << "9 to exit" << endl;
}//end showSelection

void sellProduct(dispenserType& product,
cashRegister& pCounter)
{
int amount; //variable to hold the amount entered
int amount2; //variable to hold the extra amount needed

if (product.getNoOfItems() > 0) //if the dispenser is not
//empty
{
cout << "Please deposit " << product.getCost()
<< " cents" << endl;
cin >> amount;

if (amount < product.getCost())
{
cout << "Please deposit another "
<< product.getCost()- amount
<< " cents" << endl;
cin >> amount2;
amount = amount + amount2;
}

if (amount >= product.getCost())
{
pCounter.acceptAmount(amount);
product.makeSale();
cout << "Collect your item at the bottom and "
<< "enjoy." << endl;
}
else
cout << "The amount is not enough. "
<< "Collect what you deposited." << endl;

cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
<< endl << endl;
}
else
cout << "Sorry, this item is sold out." << endl;
}//end sellProduct

]













User is offlineProfile CardPM
+Quote Post

papuccino1
RE: Will Not Compile. Need Help
22 Apr, 2008 - 07:23 AM
Post #2

D.I.C Head
**

Joined: 2 Mar, 2008
Posts: 91


My Contributions
Please use the Code Tags...
User is offlineProfile CardPM
+Quote Post

ITChief
RE: Will Not Compile. Need Help
22 Apr, 2008 - 10:39 AM
Post #3

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
The current sellProduct() function only allows the user two chances to enter enough money to buy the product. Rewrite this function so that it keeps prompting the user until enough money is entered. Build and compile the application with its modified code. The prob I'm having that the compiler gave me 309 error codes.


[ / candyMachine Header File

#include <string>

using namespace std;

class cashRegister
{
public:
int getCurrentBalance() const;
//Function to show the current amount in the cash
//register.
//Postcondition: The value of cashOnHand is returned.

void acceptAmount(int amountIn);
//Function to receive the amount deposited by
//the customer and update the amount in the register.
//Postcondition: cashOnHand = cashOnHand + amountIn;

cashRegister(int cashIn = 500);
//Constructor
//Sets the cash in the register to a specific amount.
//Postcondition: cashOnHand = cashIn;
// If no value is specified when the
// object is declared, the default value
// assigned to cashOnHand is 500.

private:
int cashOnHand; //variable to store the cash
//in the register
}; / ]





[ / dispenserType Header File
#include <string>
#include <iostream>
#include "cashResgister.h"

using namespace std;

class dispenserType
{
public:
int getNoOfItems() const;
//Function to show the number of items in the machine.
//Postcondition: The value of numberOfItems is returned.

int getCost() const;
//Function to show the cost of the item.
//Postcondition: The value of cost is returned.

void makeSale();
//Function to reduce the number of items by 1.
//Postcondition: numberOfItems--;

dispenserType(int setNoOfItems = 50, int setCost = 50);
//Constructor
//Sets the cost and number of items in the dispenser
//to the values specified by the user.
//Postcondition: numberOfItems = setNoOfItems;
// cost = setCost;
// If no value is specified for a
// parameter, then its default value is
// assigned to the corresponding member
// variable.

private:
int numberOfItems; //variable to store the number of
//items in the dispenser
int cost; //variable to store the cost of an item
}; / ]



[ / #include <iostream>
#include "candyMachine.h"

using namespace std;

int cashRegister::getCurrentBalance() const
{
return cashOnHand;
}

void cashRegister::acceptAmount(int amountIn)
{
cashOnHand = cashOnHand + amountIn;
}

cashRegister::cashRegister(int cashIn)
{
if (cashIn >= 0)
cashOnHand = cashIn;
else
cashOnHand = 500;
}

int disspenserType::getNoOfItems() const
{
return numberOfItems;
}

int dispenserType::getCost() const
{
return cost;
}

int dispenserType::makeSale()
{
numberOfItems--;
}

dispenserType::dispenserType(int setNoOfItems, int setCost)
{
if (setNoOfItems >= 0)
numberOfItems = setNoOfItems;
else
numberOfItems = 50;

if (setCost >= 50;
cost = 50;
} / ]





[ / #include <iostream>
#include "candyMachine.h"

using namespace std;

void showSelection();
void sellProduct(dispenserType& product,
cashRegister& pCounter);

int main()
{
cashRegister counter;
dispenserType candy(100, 50);
dispenserType chips(100, 65);
dispenserType gum(75, 45);
dispenserType cookies(100, 85);

int choice; //variable to hold the selection

showSelection();
cin >> choice;

while (choice != 9)
{
switch (choice)
{
case 1:
sellProduct(candy, counter);
break;
case 2:
sellProduct(chips, counter);
break;
case 3:
sellProduct(gum, counter);
break;
case 4:
sellProduct(cookies, counter);
break;
default:
cout << "Invalid selection." << endl;
}//end switch

showSelection();
cin >> choice;
}//end while

return 0;
}//end main

void showSelection()
{
cout << "*** Welcome to Shelly's Candy Shop ***" << endl;
cout << "To select an item, enter " << endl;
cout << "1 for Candy" << endl;
cout << "2 for Chips" << endl;
cout << "3 for Gum" << endl;
cout << "4 for Cookies" << endl;
cout << "9 to exit" << endl;
}//end showSelection

void sellProduct(dispenserType& product,
cashRegister& pCounter)
{
int amount; //variable to hold the amount entered
int amount2; //variable to hold the extra amount needed

if (product.getNoOfItems() > 0) //if the dispenser is not
//empty
{
cout << "Please deposit " << product.getCost()
<< " cents" << endl;
cin >> amount;

if (amount < product.getCost())
{
cout << "Please deposit another "
<< product.getCost()- amount
<< " cents" << endl;
cin >> amount2;
amount = amount + amount2;
}

if (amount >= product.getCost())
{
pCounter.acceptAmount(amount);
product.makeSale();
cout << "Collect your item at the bottom and "
<< "enjoy." << endl;
}
else
cout << "The amount is not enough. "
<< "Collect what you deposited." << endl;

cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
<< endl << endl;
}
else
cout << "Sorry, this item is sold out." << endl;
}//end sellProduct / ]

This post has been edited by ITChief: 22 Apr, 2008 - 10:58 AM
User is offlineProfile CardPM
+Quote Post

corliss
RE: Will Not Compile. Need Help
22 Apr, 2008 - 10:50 AM
Post #4

D.I.C Head
Group Icon

Joined: 25 Oct, 2006
Posts: 119



Thanked: 1 times
Dream Kudos: 50
My Contributions
open square bracket
code
close suare bracket

/****************
*****************
**your code in here
****************/
open square bracket
/code
close square bracket
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:25PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month