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?


#ifndef STORE_H
#define STORE_H

#include <iostream>
#include <iomanip>

using namespace std; 

class Store
    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;

    int ProductIDNumber;
    char Description [25];
    int ManufacturersIDNumber;
    double Price;
    double Percentage;
    int Inventory;

Implementation file

#include "Store.h"

    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<<setw(45)<<"Office Supply Product Information"<<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: "



double const &Store::RetailPrice()const


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<< "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);


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

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

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.

Edited 4 Years Ago by mkaynutty

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

This article has been dead for over six months. Start a new discussion instead.