So I'm trying to right a code to output some simple data using classes. Everything works accept the retail price function. It's suppose to calculate and output the retail price but it only outputs 0 no matter what numbers I eneter. Can anyone give me some suggestions on how to fix this?

Header

#ifndef STORE_H
#define STORE_H

#include <iostream>
#include <iomanip>

using namespace std; 

class Store
{
public:
    Store( );
    Store (int, char[], int, double, double, int, double);

    int GetProductIDNumber ( )const;
    char const* GetDescription ( )const;
    int GetManufacturersIDNumber ( )const;
    double GetPrice ( )const;
    double GetPercentage ( )const;
    int GetInventory ( )const; 
    void Display ()const;
    double const &RetailPrice ( )const;


private:
    int ProductIDNumber;
    char Description [25];
    int ManufacturersIDNumber;
    double Price;
    double Percentage;
    int Inventory;
};
#endif

Implementation file

#include "Store.h"

Store::Store()
{
    ProductIDNumber = 0;
    Description[24] = '\0';
    ManufacturersIDNumber = 0;
    Price = 0;
    Percentage = 0;
    Inventory = 0;

}
Store::Store (int InitProductIDNumber, char InitDescription[], int InitManufacturersIDNumber, 
              double InitPrice, double InitPercentage, int InitInventory, double InitRetailPrice)
{
    ProductIDNumber = InitProductIDNumber;
    strcpy_s( Description, InitDescription );
    ManufacturersIDNumber = InitManufacturersIDNumber;
    Price = InitPrice;
    Percentage = InitPercentage;
    Inventory = InitInventory;

}

int Store::GetProductIDNumber() const
{
    return( ProductIDNumber );
}

char const* Store::GetDescription() const
{
    return( Description );
}

int Store::GetManufacturersIDNumber() const
{
    return( ManufacturersIDNumber );
}

double Store::GetPrice() const
{
    return ( Price );
}

double Store::GetPercentage() const
{
    return( Percentage );
}

int Store::GetInventory() const
{
    return( Inventory );
}

void Store::Display() const
{
     cout<<"12345678901234567890123456789012345678901234567890"<<endl;
    cout<<endl;

cout<<"============================================================="<<endl;

cout<<setw(45)<<"Office Supply Product Information"<<endl;

cout<<"============================================================="<<endl;
cout<<"============================================================="<<endl;
cout<<setw(30)<<setfill(' ')
    <<"Identification Number: "
    <<setw (15)<< GetProductIDNumber()<<endl;

cout<<setw(20)<<setfill(' ')
    <<"Description: "
    <<setw (23) << GetDescription()<<endl;

cout<<setw(21)<<setfill(' ')
    <<"Manufacturer: "
    <<setw(22)<< GetManufacturersIDNumber()<<endl;

cout<<setw(24)<<setfill(' ')
    <<"Wholesale Price: "
    <<setw(19)<< GetPrice ()<<endl;

cout<<setw(22)<<setfill(' ')
    <<"Mark-up Price: "
    <<setw(21)<< GetPercentage()<<endl;

cout<<setw(25)<<setfill(' ')
    <<"Quanity In stock: "
    <<setw(18)<<GetInventory()<<endl; 

    cout<<"============================================================="<<endl;

}

double const &Store::RetailPrice()const
{

    return((Price*Percentage)+Price);
}

Client Code

#include "Store.h"

int main()
{
    int InitProductIDNumber = 0;
    char InitDescription[24] = "\0";
    int InitManufacturersIDNumber = 0;
    double InitPrice = 0;
    double InitPercentage = 0;
    int InitInventory = 0;
    double InitRetailPrice = 0;

    char NextChar= '\0';
    char ContinuationFlag = 'Y';

    while (toupper(ContinuationFlag) == 'Y')
    {
        cout<<endl;
        cout<< "Enter the products ID Number: "<<endl;
        cin>> InitProductIDNumber;
        cout<< "Enter the products Manufacturer's ID Number: "<<endl;
        cin>> InitManufacturersIDNumber;
        cout<< "Enter the products wholesale price: "<<endl;
        cin>> InitPrice;
        cout<< "Enter the product's mark-up percentage: "<<endl;
        cin>> InitPercentage;
        cout<< "Enter the product's description: "<<endl;

        NextChar = cin.peek();
        if ( NextChar =='\n')
        {
            cin.ignore( );
        }
        cin.get (InitDescription, 24);

        cout<< "Enter the quantity of the product in stock: "<<endl;
        cin>> InitInventory;

        Store InventoryItem (InitProductIDNumber, InitDescription, InitManufacturersIDNumber, InitPrice, InitPercentage, 
            InitInventory, &RetailPrice);

        InventoryItem.Display();

        cout<<endl;
        **cout<< "Office Supply Product Retail Price: "<<&RetailPrice()<<endl;** //This is where the output of retail function should be

        cout<<endl;
        cout<<" Do you wish to enter any more products?"<<endl;
        cout<<endl;
        cout<< "Enter 'Y' or 'N'"<<endl;
        cin>> ContinuationFlag;
    }
    return 0;
}

Recommended Answers

All 8 Replies

line 40: That ctr is expecting a double as the last parameter, not a pointer. Remove the & before RetailPrice.

I fixed that and changed a few other things, in line 45 I put InitRetailPrice instead of &Retail Price(), I took the & out of the function declaration in the header file. So now it runs but again doesn't calculate the retail price for me.

repost lines 39 and 40 so we can see what changes you made.

Store InventoryItem (InitProductIDNumber, InitDescription, InitManufacturersIDNumber, InitPrice, InitPercentage, 
            InitInventory, InitRetailPrice);


cout<< "Office Supply Product Retail Price: "<<InitRetailPrice<<endl;

So now it runs but again doesn't calculate the retail price for me.

Because it's not calling RetailPrince() function. Your program is passing a pointer to the function, not calling the function itself. This is how it should be coded, note the last parameter is calling the function.

Store InventoryItem (InitProductIDNumber, InitDescription, InitManufacturersIDNumber, InitPrice, InitPercentage, 
            InitInventory, RetailPrice());

I changed that and changed the intialization of it so it reads

double RetailPrice = 0;

and this is the error I got

error C2064: term does not evaluate to a function taking 0 arguments

Can you post the code you have now?

You can't have variable names the same as function names.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.