0

hi all. The output I get always shows some really random numbers, such as -7883933849400000000000000.00 . Is there any thing i'm missing...any help would be really appreciated. PLEASE

// Specification file for the Inventory class.
#ifndef INVENTORY_H
#define INVENTORY_H

class Inventory
{
	private:
		int itemNum;
		int quantity;
		double cost;
		double totalCost;
	public:
		Inventory()			// Constructor
		{
			itemNum = 0;
			quantity = 0;
			cost = 0;
			totalCost = 0;
		}
		Inventory(int itemNum, int quantity, double cost)	// Constructor
		{
			itemNum = getItemNum();
			quantity = getQuantity();
			cost = getCost();
			setTotalCost(quantity, cost);
		}

		void setItemNum(int)
		{
			itemNum = itemNum;
		}
		void setQuantity(int)
		{
			quantity = quantity;
		}
		void setCost(double)
		{
			cost = cost;
		}
		void setTotalCost(int, double)
		{
			totalCost = quantity * cost;
		}

		int getItemNum()
		{
			return itemNum;
		}
		int getQuantity()
		{
			return quantity;
		}
		double getCost()
		{
			return cost;
		}
		double getTotalCost()
		{
			return totalCost;
		}
};
#endif

//Driver program(cpp. file)
#include "stdafx.h"
#include "Inventory.h"
#include <iostream>
#include <iomanip>
using namespace std;


int main()
{
	int itemNum;			// The item number
	int quantity;			// Number of items on hand
	double cost;			// The item cost
	double totalCost;		// The item total cost
	
	cout << " Please enter an item number: " << endl;
	cin >> itemNum;
	// Input validation
	while (itemNum < 0)
	{
		cout << " Invalid input. Please enter a positive value for item number.";
		cin >> itemNum;
	}
	cout << " Please enter the quantity of the item: ";
	cin >> quantity;
	// Input validation
	while (quantity < 0)
	{
		cout << " Invalid input. Please enter a positive value for quantity.";
		cin >> quantity;
	}
	cout << " Please enter the price of the item: ";
	cin >> cost;
	// Input validation
	while (cost < 0)
	{
		cout << " Invalid input. Please enter a positive value for the price.";
		cin >> cost;
	}
	
	Inventory inventory(itemNum, quantity, cost);
	itemNum = inventory.getItemNum();
	quantity = inventory.getQuantity();
	cost = inventory.getCost();
	totalCost = inventory.getTotalCost();

	cout << " Item Number: " << itemNum << endl;
	cout << " Quantity: " << quantity << endl;
	cout << " Cost: $ " << cost << endl;
	cout << " Total Cost: $ " << fixed << setprecision(2) << totalCost << endl;
	return 0;
}

Edited by peter_budo: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Salem
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.