C++ | Creating a bill for shop

Introduction

The program to create a bill for a shop. The program is not flexible as it can make bill of only three products which is does not make it flexible. you have to add more products to the program to make bill of more products which makes it non-flexible.So you can make use of loop to make the program flexible. Go enjoy the program.Lets begin……..

Program to Create a Bill for shop

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int i1,i2,i3,q1,q2,q3,p1,p2,p3,a1,a2,a3,ta;
//Input the 1st product details and save them in their respective variables
cout<<"Enter 1st product code"<<endl;
cin>>i1;
cout<<"Enter 1st product price"<<endl;
cin>>p1;
cout<<"Enter 1st product quantity"<<endl;
cin>>q1;
//draw line for neatness
cout<<"-----------------------------------"<<endl;
//Input the 2nd product details and save them in their respective variables
cout<<"Enter 2nd product code"<<endl;
cin>>i2;
cout<<"Enter 2nd product price"<<endl;
cin>>p2;
cout<<"Enter 2nd product quantity"<<endl;
cin>>q2;
//draw line for neatness
cout<<"-----------------------------------"<<endl;
//Input the 3rd product details and save them in their respective variables
cout<<"Enter 3rd product code"<<endl;
cin>>i3;
cout<<"Enter 3rd product price"<<endl;
cin>>p3;
cout<<"Enter 3rd product quantity"<<endl;
cin>>q3;
//draw line for neatness
cout<<"-----------------------------------"<<endl;
//calculate amount and total and save them in 'a1','a2'and 'a3'
a1=p1*q1;
a2=p2*q2;
a3=p3*q3;
ta=a1+a2+a3;
//show the bill
cout<<"Item \t Price \t Qty \t Amount"<<endl;
cout<<i1<<"\t"<<p1<<"\t"<<q1<<"\t"<<a1<<endl;
cout<<i2<<"\t"<<p2<<"\t"<<q2<<"\t"<<a2<<endl;
cout<<i3<<"\t"<<p3<<"\t"<<q3<<"\t"<<a3<<endl;
//Show total
cout<<"-----------------------------------"<<endl;
cout<<"Total amount = "<<ta;
//get character
getch();
}

Output

Enter 1st product code
123
Enter 1st product price
12
Enter 1st product quantity
3
———————————–
Enter 2nd product code
143
Enter 2nd product price
10
Enter 2nd product quantity
12
———————————–
Enter 3rd product code
138
Enter 3rd product price
5
Enter 3rd product quantity
9
———————————–
Item     Price     Qty    Amount
123        12           3        36
143        10         12       120
138        5            9         45
———————————–
Total amount = 201

How does it work

  1. You enter the details of 1st product and is saved in variables.
  2. You enter the details of 2nd product and is saved in variables.
  3. You enter the details of 3rd product and is saved in variables.
  4. The amount1 is calculated according to  formula and is saved in ‘a1’.
  5. The amount2 is calculated according to formula and is saved in ‘a2’.
  6. The amount3 is calculated according to formula and is saved in ‘a3’.
  7. The Total amount is calculated according to formula and is saved in ‘ta’
  8. The bill is printed according to given couts and cins.
  9. The total amount is printed by cout.

Extending it

The program can be extended by taking more products details and calculating the amount and making total of it. You can take the more number of product into account and print the bill for shop. You can even use loop for taking more number of products by entering the number of products that makes the program flexible.

Explanation.

  1. Include ‘iostream.h’ and ‘conio.h’ files.
  2. Add void main.
  3. Start program by first clearing the screen.
  4. Declare the variables as int (name the as you want.)
  5. Add cout and cin of variables of the products details.(as shown in program)
  6. Calculate the amount and save them in amount variable.
  7. Calculate the total and save them in ‘ta’ variable
  8. Cout the bill.
  9. Cout the total amount.

At the end

You learnt creating the c++ program of Creating a bill for shop. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

2 thoughts on “C++ | Creating a bill for shop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s