little Billing pack

C, C++, Visual C++, C++.Net Topics
Post Reply
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

little Billing pack

Post by Face » Thu Nov 11, 2010 7:24 pm

I wrote little code.I will use this new topic to make some changes in it.Because our C++ topic is becoming bigger & bigger.

Here is my little code

Code: Select all

//G-sparkz little billing Pack Devoloped

#include<iostream>

using namespace std;

int main()
{
    int Paper,Quantity,Total;
    char Name[50];
    
    cout<<"Welcome to G-sparkZ Billing Pack"<<endl<<endl;
    
    cout<<"Please enter your name"<<endl;
    cin>>Name;
    cout<<Name <<" entered the G-SparkZ Billing system "<<endl<<endl;
    
    cout<<"Paper size codes [ A4=4 A3=3 ] "<<endl<<endl;
    cout<<"Enter your paper size code ";
    cin>>Paper;
    
    if(Paper==4)
    Paper=5;
    else if (Paper==3)
    Paper=10;
    else
    cout<<"wronge paper";
    
    cout<<"How many pages ";
    cin>>Quantity;
    
    cout<<"paper - A"<<Paper<< " Pages - "<< Quantity<<endl;
    
    Total=Paper*Quantity;
    
    cout<<"Total price - "<<Total<<endl;
    
    system("pause");
    }
I wanna do some changes here.

1.I wanna stop my program if user input wrong paper code.
2.I wanna make some empty lines after "how many pages line"& after entering my name G-sparkZ.
billing 1.png
billing 1.png (13.78 KiB) Viewed 6501 times
Last edited by Neo on Thu Nov 11, 2010 9:45 pm, edited 1 time in total.
Reason: Added image to post
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: little Billing pack

Post by Nipuna » Thu Nov 11, 2010 7:27 pm

1.I wanna stop my program if user input wrong paper code.
For that you have to add

Code: Select all

If
Command or something like that. but I didn't studied those yet.

Others will help you :)
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: little Billing pack

Post by Face » Thu Nov 11, 2010 7:42 pm

Yeah,nipuna.
I am waiting for NEO
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: little Billing pack

Post by Neo » Thu Nov 11, 2010 10:16 pm

Code: Select all

void main()
{
    int Paper,Quantity,Total;
    char Name[50];
   
    cout<<"Welcome to G-sparkZ Billing Pack"<<endl<<endl;
   
    cout<<"Please enter your name"<<endl;
    cin>>Name;
    cout << "\n\n\n\n" <<Name <<" entered the G-SparkZ Billing system "<<endl<<endl;
   
    cout<<"Paper size codes [ A4=4 A3=3 ] "<<endl<<endl;
    cout<<"Enter your paper size code ";
    cin>>Paper;
   
    if(Paper==4){
		Paper=5;
	}
    else if (Paper==3){
		Paper=10;
	}
    else{
		cout<<"wronge paper" << endl;
		return;
	}
   
    cout<<"How many pages " << "\n\n\n";
    cin>>Quantity;
   
    cout<<"paper - A"<<Paper<< " Pages - "<< Quantity<<endl;
   
    Total=Paper*Quantity;
   
    cout<<"Total price - "<<Total<<endl;
   
    system("pause");
}
Notice I have added multiple "\n" to make multiple end lines. "\n" is equals to endl.
You can also put multiple endls as well. Ex: << endl << endl << endl.......

The other one is "return;". See I used it after "wrong paper" to exit the application form there without proceeding further.
Note that I changed "int main()" to "void main()" again. Do not use anything without a meaning.
However, if you use int main(), make sure to use return x; where x is a number.

Good luck!
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: little Billing pack

Post by Face » Thu Nov 11, 2010 11:03 pm

Thanks NEO.But I wanna stop my program when user input a wrong code * display wrong code.When I use return it exits when press enter.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: little Billing pack

Post by Neo » Fri Nov 12, 2010 12:09 am

Yes...

Find code,

Code: Select all

      cout<<"wronge paper" << endl;
      return;
Replace with,

Code: Select all

      cout<<"wronge paper" << endl;
      system ("pause");
      return;
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: little Billing pack

Post by Nipuna » Fri Nov 12, 2010 7:45 am

Hey G-sparkZ

Can you remember that I told you about

Code: Select all

If
?

Thanks Neo for Helping Us. But I couldn't study C++ in these days. If I did I would help here according to my Knowledge.

And I am Also confused about some things such as the return thing and the void main thing and int main thing :?
Those Feel Me that i didn't studied well. :?
Can you Explain Me those in Simple words or in Sinhala :) You are doing Great work because you try to Explain everything you know that related to those Stuffs. But I like to know them in Simple language. Can you tell me those without getting mad? Because I asked this i think in lankatalk too.

Thanks
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: little Billing pack

Post by Neo » Fri Nov 12, 2010 11:32 am

And I am Also confused about some things such as the return thing and the void main thing and int main thing :?
Those Feel Me that i didn't studied well. :?
Can you Explain Me those in Simple words or in Sinhala :) You are doing Great work because you try to Explain everything you know that related to those Stuffs. But I like to know them in Simple language. Can you tell me those without getting mad? Because I asked this i think in lankatalk too.
See https://robot.lk/viewtopic.php?f=8&t=2053
Post Reply

Return to “C/C++ Programming”