Page 1 of 1

little Billing pack

Posted: Thu Nov 11, 2010 7:24 pm
by Face
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 7490 times

Re: little Billing pack

Posted: Thu Nov 11, 2010 7:27 pm
by Nipuna
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 :)

Re: little Billing pack

Posted: Thu Nov 11, 2010 7:42 pm
by Face
Yeah,nipuna.
I am waiting for NEO

Re: little Billing pack

Posted: Thu Nov 11, 2010 10:16 pm
by Neo

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!

Re: little Billing pack

Posted: Thu Nov 11, 2010 11:03 pm
by Face
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.

Re: little Billing pack

Posted: Fri Nov 12, 2010 12:09 am
by Neo
Yes...

Find code,

Code: Select all

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

Code: Select all

      cout<<"wronge paper" << endl;
      system ("pause");
      return;

Re: little Billing pack

Posted: Fri Nov 12, 2010 7:45 am
by Nipuna
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

Re: little Billing pack

Posted: Fri Nov 12, 2010 11:32 am
by Neo
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