I need help on modularization of this, and exception handling..

#include
#include
using namespace std;


void main()
{
int ch,D1000,D500,D200,D100,D50,D20,D10,D5,D1,DC25,denm=0;
char ans;
double cart=0,item=0,vat=0;

string a="[1]Sony Ericsson J120i - 3,189.50 Pesos";
string b="[2]Sony Ericsson K200i - 4,289.50 Pesos";
string c="[3]Sony Ericsson K320i - 4,889.50 Pesos";
string d="[4]Sony Ericsson K510i - 5,289.50 Pesos";
string e="[5]Sony Ericsson K550i - 9,189.50 Pesos";
string f="[6]Sony Ericsson K618i - 9,889.50 Pesos";
string g="[7]Sony Ericsson K810i - 15,989.50 Pesos";
string h="[8]Sony Ericsson W200i - 5,589.50 Pesos";
string i="[9]Sony Ericsson W300i - 7,189.50 Pesos";
string j="[10]Sony Ericsson W850i - 14,089.50 Pesos";
string k="[11]Sony Ericsson W880i - 16,189.50 Pesos";
string l="[12]Sony Ericsson Z310i - 4,789.50 Pesos";
string m="[13]Sony Ericsson Z610i - 10,789.50 Pesos";
string n="[14]Sony Ericsson P990i - 16,489.50 Pesos";
string o="[15]Sony Ericsson P1i - 26,589.50 Pesos";
menu:cout<<"****************************************************************************";
cout<<" CASHIER 1.0 ";
cout<<" SONY ERICSSON PHONES ";
cout<<" pricelist (as of 2007) "<<endl;
cout<<"****************************************************************************";
cout<<"
";
cout<<" Please choose the phone you want.
";
cout<<" "<<a<<endl;
cout<<" "<<b<<endl;
cout<<" "<<c<<endl;
cout<<" "<<d<<endl;
cout<<" "<<e<<endl;
cout<<" "<<f<<endl;
cout<<" "<<g<<endl;
cout<<" "<<h<<endl;
cout<<" "<<i<<endl;
cout<<" "<<j<<endl;
cout<<" "<<k<<endl;
cout<<" "<<l<<endl;
cout<<" "<<m<<endl;
cout<<" "<<n<<endl;
cout<<" "<<o<<endl;
cout<<" Press 16 to exit.
";
cout<<"
";
cin>>ch;

if(ch<1||ch>16)goto menu;
switch(ch)
{
case 1:cout<<a;
item = 3189.99;break;
case 2:cout<<b;
item = 4289.99;break;
case 3:cout<<c;
item = 4889.99;break;
case 4:cout<<d;
item = 5289.99;break;
case 5:cout<<e;
item = 9189.99;break;
case 6:cout<<f;
item = 9889.99;break;
case 7:cout<<g;
item = 15989.99;break;
case 8:cout<<h;
item = 5589.99;break;
case 9:cout<<i;
item = 7189.99;break;
case 10:cout<<j;
item = 14089.99;break;
case 11:cout<<k;
item = 16189.99;
case 12:cout<<l;
item = 4789.99;break;
case 13:cout<<m;
item = 10789.99;break;
case 14:cout<<n;
item = 16489.99;break;
case 15:cout<<o;
item = 26589.99;break;
case 16:goto end;break;
}
cart = item + cart;
cout<<"
";
cout<<"
Sub purchase total: "<<cart<<" Pesos"<<endl;
cout<<" Do You Wish To Add another phone to your cart?[y/n]";
cin>>ans;
cout<<"
";
cout<<"
";
cout<<"
";
if(ans=='y'||ans=='Y'){
goto menu;
item = 0;}
else{
vat = (cart*.12);
cout<<"
Total sales: "<<cart<<" Pesos"<<endl;
cout<<"
Total vat: "<<vat<<" Pesos"<<endl;}
cout<<"
DENOMINATION";
cout<<"
";

D1000 = cart/1000;
denm = cart - (D1000*1000);
cout<<"
1000 pesos: x"<<D1000<<endl;
if (denm >= 500){
D500 = denm/500;
denm = denm - (D500*500);
cout<<"
500 pesos: x"<<D500<<endl;}
if (denm >= 200){
D200 = denm/200;
denm = denm - (D200*200);
cout<<"
200 pesos: x"<<D200<<endl;}
if (denm >= 100){
D100 = denm/100;
denm = denm - (D100*100);
cout<<"
100 pesos: x"<<D100<<endl;}
if (denm >= 50){
D50 = denm/50;
denm = denm - (D50*50);
cout<<"
50 pesos: x"<<D50<<endl;}
if (denm >= 20){
D20 = denm/20;
denm = denm - (D20*20);
cout<<"
1 pesos: x"<<D20<<endl;}
if (denm >= 10){
D10 = denm/10;
denm = denm - (D10*10);
cout<<"
10 pesos: x"<<D10<<endl;}
if (denm >= 5){
D5 = denm/5;
denm = denm - (D5*5);
cout<<"
5 pesos: x"<<5<<endl;}
if (denm >= 1){
D1 = denm/1;
denm = denm - (D1*1);
cout<<"
1 pesos: x"<<D1<<endl;}
if (denm >= .25){
DC25 = denm/.25;
denm = denm - (DC25*.25);
cout

Comments

  • Ok, the first thing you have to do is proper indention. Please use code tags when posting code to preserve the indention, making the code appear like this:

    [code]
    if(x)
    {
    do_something();
    }
    [/code]

    Syntax is

    [leftbr]code[rightbr]
    /* code goes here. */
    [leftbr]/code[rightbr]

    Second thing you need to do is to only have one line of code at one row. Putting several of them on one line is legal C++, but considered very poor style, because it is unreadable.

    Including empty rows here and there in the code also makes it more readable. Try to put segments of code belonging together in text segments of its own.

    You also need to make one single array of all those strings, instead of using several variables.

    Also, main() must always be of the format int main() in C++, everything else is non-standard code which won't compile on C++ compilers.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion