Feb 28, 2015 at 12:06am UTC
I'm on my second class of C++ need help trying to figure out why I'm getting an error. The compiler says "expression must have bool type" The code has two class objects.
#include "InventoryItem.h"
#include "CashRegister.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int INVSZ = 5; //Inventory size = 5
InventoryItem store[INVSZ]; //array of inventory
int itemnum, units; //local variables
char doAgain;
Cash_Register reg; //instance of cash register class
//Inventory items
store[0].setDescription("Adjustable Wrench");
store[0].setCost(9.10);
store[0].setUnits(10);
store[1].setDescription("Screwdriver");
store[1].setCost(5.20);
store[1].setUnits(20);
store[2].setDescription("Pliers");
store[2].setCost(7.30);
store[2].setUnits(5);
store[3].setDescription("Ratchet");
store[3].setCost(11.00);
store[3].setUnits(7);
store[4].setDescription("Socket Wrench");
store[4].setCost(12.00);
store[4].setUnits(10);
cout << "#" << setw(25) << "Item" << setw(15) << "qty on Hand" << endl;
cout << "-------------------------------------------------------------\n";
for (int i = 0; i < INVSZ; i++)
{
cout << store[i].getDescription() << (i + 1) << " "
<< store[i].getUnits() << " " << endl;
}
do
{
cout << "Which item above is being purchased? ";
cin >> itemnum;
do
{
cout << "How many units? ";
cin >> units;
} while (!store[itemnum - 1].subtractUnits(units)); //error code store
reg.CalcPurchPrice(store[itemnum - 1].getCost(), units);
cout << "#" << setw(25) << "Item" << setw(15) << "qty on Hand" << endl;
cout << "--------------------------------------------------------------" << endl;
cout << "Subtotal: $" << reg.getSubTotal() << endl;
cout << "Sales Tax: $" << reg.getTax() << endl;
cout << "Total: $" << reg.getTotal() << endl;
cout << "Would you like to purchase another item?";
cin >> doAgain;
} while (doAgain == 'Y');
system("pause");
return 0;
}
#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H
#include <cstring> // Needed for strlen and strcpy
// Constant for the description's default size
const int DEFAULT_SIZE = 51;
class InventoryItem
{
private:
char *description; // The item description
double cost; // The item cost
int units; // Number of units on hand
// Private member function.
void createDescription(int size, char *value);
public:
// Constructor #1
InventoryItem();
// Constructor #2
InventoryItem(char *desc);
// Constructor #3
InventoryItem(char *desc, double c, int u);
// Destructor
~InventoryItem();
// Mutator functions
void setDescription(char *d);
void setCost(double c);
void setUnits(int u);
bool subtractUnits(int u);
// Accessor functions
const char *getDescription() const;
double getCost() const;
int getUnits() const;
};
#endif
Feb 28, 2015 at 3:49am UTC
Put your code in code tags < >... Also, post the error. (The line...etc...) Also post your relevant header and cpp files..