473,473 Members | 4,189 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is there any mistake in this program code? it is not showing the total bill.

1 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. class Purchased_item
  5. {
  6.       private:
  7.       static int itemno;         
  8.       int price;                   
  9.       int quantity;                
  10.       public:
  11.       Purchased_item() {
  12.       this -> price = 0;
  13.       this -> quantity = 0;
  14.       }
  15.  
  16.       int getprice()
  17.       {
  18.       cout<<"Price: ";
  19.       cin>>this -> price;
  20.       return price;
  21.       }
  22.  
  23.       int getquantity()
  24.       {
  25.       cout<<"Quantity: ";
  26.       cin >>this -> quantity;
  27.       return quantity;
  28.       }
  29.  
  30.       static int items()
  31.       {
  32.       itemno++;
  33.       return itemno;
  34.       }
  35.  
  36. };
  37.       int Purchased_item::itemno = 0;
  38.  
  39. class Bill
  40. {
  41.       private:
  42.       int total_amount;              
  43.       Purchased_item items[5];       
  44.       public:
  45.       Bill()
  46.       {
  47.       this -> total_amount = 0;
  48.       }
  49.  
  50.       void calculate()
  51.       {
  52.       for(int i=0; i<5; i++)
  53.       {
  54.       cout<<"\nEnter price and purchased quantity of item "<< items[i].items() <<endl;
  55.       total_amount += items[i].getprice() * items[i].getquantity();
  56.       }
  57.      }
  58.  
  59.            void display()
  60.            {
  61.            cout<<"\nTotal amount to be paid is : "<<total_amount<<endl;
  62.            }
  63.  
  64. };
  65.  
  66. void  main()
  67. {
  68.      Bill b;
  69.      b.calculate();
  70.      b.display();
  71.      return 0;
  72. }
Apr 22 '07 #1
1 1076
Ganon11
3,652 Recognized Expert Specialist
The code you have here works just fine...except when I try to enter a fraction for the price. Since you have price (in Purchased_Item) and total_price (in Bill) declared as ints, I can't enter a price such as 0.99, which is more common than 1. However, after I make these changes, your program works perfectly.
Apr 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: pete | last post by:
I found it in the view source of a corporate website. <script Language="Javascript"> <!-- var keyMacro= ]; //--> </script>
23
by: Red Dragon | last post by:
I am self study C program student. Hope someone can help me with this problem. This program generates random numbers over a user defined range using call function I used the call function "...
12
by: Tiny Tim | last post by:
Hope someone can help me to overcome this problem. Case 1 is working perfectly working with one number entry. Case 2 is the problem when I tried with 2 numbers entry. Case 1. #include...
5
by: Keo932 | last post by:
Hello all, I am finishing up my program to simulate a tollbooth by using classes. What happens is cars passing by the booth are expected to pay a fifty cent toll. The program keeps track of the...
3
by: Deven Oza | last post by:
Hello everybody, I need your help to write the following procedure. I did it but dont get the out put so please help me that where I made mistake. I written the procedure just after the...
1
by: confusedprogrammer | last post by:
In the program below i need to get it, so that it will keep going through the program asks all the question and displays the results and goes back to the beginning if the user didn't select. After...
30
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
7
by: CuTe_Engineer | last post by:
hii, can you tell me plzz why my programme doesn`t work ,i don`t have any errors and every thing is fine but i don`t know why it`s not working , soo plz can you help me un finding my mistake i...
1
by: aaron5150 | last post by:
OK so here goes. I have created a table for my "employees details" including "employee number". I have also completed another table which shows orders by "employee number", details of order etc. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.