need u r help

Hello, i hope u doing well all , i have this is question and i tried to solve it but, when i run the program it does not multiplies the quantity by the price i dont know i hope u can help me with it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  #include<iostream>
#include<string>
using namespace std;
class Invoice{
int number;
string description;
int quantity;
 int price;

public:
Invoice(int n,string d,int q,int p);
int getnumber();
void setnumber();
string getdescription();
void setdescription();
int getquantity();
void setquantity();
int getprice();
void setprice();

int getInvoiceAmount();
~Invoice();
};

#include<iostream>
#include<string>
#include"invoice.h"
using namespace std;


Invoice::Invoice(int n,string d,int q,int p){
	number=n;
 description=d;
quantity=q;
 price=p;
}


int Invoice::getnumber(){return number;}
void Invoice::setnumber(){cout<<"\nEnter please the number of item\n";
cin>>number;
}
string Invoice::getdescription(){return description; }
void Invoice::setdescription(){cout<<"\nEnter please the discrepthion of item\n";
cin>>description;
}
int Invoice::getquantity(){return quantity;}
void Invoice::setquantity(){cout<<"\nEnter please the quantity\n";
cin>>quantity;
if(quantity<0)
	quantity=0;
}

int Invoice::getprice(){return price;}
void Invoice::setprice(){cout<<"\nEnter please the price of item\n";
cin>>price;
if(price<0)
	price=0;
}

int Invoice::getInvoiceAmount(){
	cout<<"\n we will see what we have \n";
	
  if((quantity<0)||(price<0))
  {
    quantity=0;
   price=0;
}
  return quantity*price;
}

Invoice::~Invoice(){cout<<"\nDestructor called\n";}


#include<iostream>
#include<string>
#include"invoice.h"
using namespace std;

int main(){
Invoice obj(067,"cofee",1,30);
cout<<"Enter please the information billow\n";
obj.setnumber();
obj.setdescription();
obj.setquantity();
obj.setprice();
obj.getInvoiceAmount();


system("pause");
return 0;
}


thank u
hmm. Have you tried doing int x = quantity*price; then returning x?

Edit: the function "getInvoiceAmount" is an integer. So after youve returned something. In this case quantity*price; you must "catch" it with an integer in main. Like this -

int invoiceAmountCatcher = obj.getInvoiceAmount(); (I think this is how it is done however I am not certain, try it)

Edit2: Just tested it my example it correct.
Last edited on
thank u so much tarrikneaj i will try it .
it does not work friend , another suggest ?
Upload your new code on www.pastebin.com and send me the link so I can take a better look.
Topic archived. No new replies allowed.