Mandatory Output it is not working and I cannot figure out why?

I am trying to get this output.


1
2
3
4
 Product Name: Orange
 Reference Number: 1123456
 Price per unit/pound: 0.99
 Stock: 34


With this code:

#include <string>
#include <iostream>

using namespace std;


class Product {
private:
string prodName;
double price;
unsigned refNum, items_remaining;


public:
Product (){
refNum=items_remaining=0; price=0; prodName="";
}
Product ( string prod, unsigned ref, double pri, unsigned stk){
refNum = ref;
items_remaining = stk;
prodName = prod;
price = pri;
}

//Add Accessors
string get_name(string name){
cin>>name;
return prodName;
}
double get_price (double cost){
cin>>cost;
return price;

}

unsigned stock (unsigned items){
cin>>items;
return items_remaining;
}
unsigned sold (unsigned items_remaining, unsigned num_sold){
items_remaining -= num_sold;
return items_remaining;
}

unsigned addToStock (unsigned items_remaining, unsigned stock_add){
stock_add +=items_remaining;
return items_remaining;

}
void info (){
cout<<"Product Name: "<<prodName<<endl;
cout<<"Reference Num: "<<refNum<<endl;
cout<<"Price per unit/pound: "<<price<<endl;
cout<<"Stock: "<<items_remaining<<endl;


}




};
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) All you've shown us is a class definition. You've shown us nothing about how calling code might be using that class. There's no way the code you've shown us, on its own, can produce the output you want, because you need, at the very least, a main() function to make use of the class.

3) Your various get*() methods look strange to me. They read data from the command line, store that data in a parameter variable, and then do nothing with it. Then, they return the value of a data member. What's the point of that?

Topic archived. No new replies allowed.