hi....

cud sum1 pls correct da code or suggest ways such dat dis prog calculates da bill even if da items r chosen at random.....unlike now.....which calculates only when da items r entered in an order....

SOURCE CODE


#include<iostream.h>
#include<conio.h>
float b=1000;
void main()
{
clrscr();
float x,b,c,amount1,amount2,amount3,p,s,j;
float d,a,o,q,r,t,u,v,w,g,h;
int m;
char choice;
char l,Y,y,N,n;
cout<<"\nwelcome 2 my grocery store!!!!";
cout<<"\nwould u like 2 see the items available for purchase(y/n)?";
cin>>choice;
if(choice=='Y'||choice=='y')
{
cout<<"the items available are:";
cout<<"\nno."<<'\t'<<"item "<<'\t'<<"quantity(b)(in grams)"<<'\t'<<"m.r.p(c)";
cout<<"\n---"<<'\t'<<"---- "<<'\t'<<"---------------------"<<'\t'<<"--------";
cout<<"\n1. "<<'\t'<<"urad dal "<<'\t'<<"1000g "<<'\t'<<"Rs.50.25";
cout<<"\n2. "<<'\t'<<"tur dal "<<'\t'<<"1000g "<<'\t'<<"Rs.60.75";
cout<<"\n3. "<<'\t'<<"tea powder "<<'\t'<<"1000g "<<'\t'<<"Rs.200.0";
cout<<"\nwould you like 2 purchase any item?(y/n)";
cin>>choice;
if(choice=='Y'||choice=='y')
{
cout<<"\nyou can purchase only two items( kindly press 'n' after purchasing two items";
m:
cout<<"\nenter the no:of the item chosen by u";
cin>>m;
if(m==1)
{
cout<<"\nenter the amount of the item u want to purchase";
cin>>x;
amount1=(x*50.25)/1000.00;
cout<<"\nthe amount to be paid is:"<<amount1<<"\n";
}
else if(m==2)
{
cout<<"\nenter the amount of item ";
cin>>x;
amount2=(x*60.75)/1000.00;
cout<<"\nthe amount 2 b paid is:"<<amount2<<"\n";
}
else if(m==3)
{
cout<<"\nenter the amount of item";
cin>>x;
amount3=(x*200.00)/1000.00;
cout<<"\nthe amount 2 be paid is:"<<amount3<<"\n";
}
cout<<"\ndo u want 2 buy another item?";
cin>>l;
if(l=='y'||l=='Y')
{
goto m;
}
else{
cout<<"\nplease wait.... ur bill is being calculated....";
}
cout<<"\nenter da no: of the items u've bought in an order(enter 0 for the second item if u've bought only one item:";
cin>>s>>j;
if(s==1&&j==0)
{
o=amount1;
cout<<"\nthe total bill is:"<<o;
}
else if(s==1&&j==1)
{
p=amount1+amount1;
cout<<"\nthe total bill is:"<<p;
}
else if(s==1&&j==2)
{
q=amount1+amount2;
cout<<"\nthe total bill is:"<<q;
}
else if(s==1&&j==3)
{
r=amount1+amount3;
cout<<"\nthe total bill is:"<<r;
}
else if(s==2&&j==0)
{
a=amount2;
cout<<"\nthe total bill is:"<<a;
}
else if(s==2&&j==1)
{
t=amount2+amount1;
cout<<"\nthe total bill is:"<<t;
}
else if(s==2&&j==2)
{
u=amount2+amount2;
cout<<"\nthe total bill is:"<<u;
}
else if(s==2&&j==3)
{
v=amount2+amount3;
cout<<"\nthe total bill is:"<<v;
}
else if(s==3&&j==0)
{
w=amount3;
cout<<"\nthe total bill is:"<<w;
}
else if(s==3&&j==1)
{
g=amount3+amount1;
cout<<"\nthe total bill is:"<<g;
}
else if(s==3&&j==2)
{
h=amount3+amount2;
cout<<"\nthe total bill is:"<<h;
}
else if(s==3&&j==3)
{
d=amount3+amount3;
cout<<"\nthe total bill is:"<<d;
}

cout<<"\nplease pay the requested amount";
cout<<"\nthank you.please visit again";
}
else if(choice=='N'||choice=='n')
{
cout<<"\nthanks for visiting my store !!!";
}
}
else if(choice=='N'||choice=='n')
{
cout<<"\nthank you.kindly try purchasing the next time u visit the store!!!!!";
}
getch();
}
Last edited on
cud sum1 pls correct da code or suggest ways such dat dis prog calculates da bill even if da items r chosen at random.....unlike now.....which calculates only when da items r entered in an order....

The procedure is as follows:
1. Learn how to write properly.
2. Talk to programmers.
The steps may not be reordered.

Some of us have spent many years mastering the English language and find it offensive when someone decides they're above proper grammar and spelling.

Edit your post so that you don't sound like you suffered from repeated head trauma and wrap your code around [code][/code] tags and we'll take a look at it.
Last edited on
That is the urban dictionary for you
stop using it and you'll turn into someone with no life
What gets me here is the glaring logical flaw that someone who is willing to type out some 70, 80 odd lines of code is not willing to type three letters "t" "h" "e" and takes "da" shortcut to save a keystroke.

cud sum1 pls correct da code or suggest ways such dat dis prog calculates da bill even if da items r chosen at random.....unlike now.....which calculates only when da items r entered in an order....

cout<<"\nenter the amount of the item u want to purchase";

cout<<"\nthe amount 2 b paid is:"<<amount2<<"\n";


LOL!!
That is 2 much :)
It could entertain me four hours!!
Good luck getting people to use such an "urban" software.

Anyway Sasha, thanks for da comedy :).

To be honest, there R some problems with "da code":
- don't use da conio.h header, it isn't from da standard C++ library, :)
It is bad because it is available only on Windows, so it makes ur code platform dependent
- because u can't use da conio.h header, u can't use da functions from conio.h
So don't use clrscr(), getch(), etc. :)
- don't use a chain of if else if else if, etc.No one will understand your code. Maybe not even u.
Dis way of programming is very bad.Instead of using a never ending chain of if else if... , use a
switch statement instead.
- and da biggest problem of dem all: Don't use void main().It's int main() :)
- also u forgot to specify da namespace.Either ypu specify it directly for each keyword, such as
std::cout
or u write using namespace std; before da main();
- is ur code C++ or C? If it is C++ than it's #include<iostream> .
iostream.h is an old header.It doesn't even come with ur compiler.
- don't use variables names such as l. Is it "one", "el", or "ai"? You have a variable named l.It is "el" , but it's hard to tell

I hope that u understood what i said.As you can see, it's kind of hard, but very funny, to read such "urban" source code :).

Sasha, i hope you understand I wasn't making fun of you.If it appeared this way, than I apologise. Honestly, I wasn't trying to make fun of you. I was just making fun of "da situation".


Most of your problem come from using badly if else if else if,etc. statements.If you switch them with switch statements, then your code will be easy to understand.The way it is now, it doesn't even compile.
Last edited on
@andrei c - Haha, I just fell out of my chair from laughter!
Hy again Sasha!
Here is a modified version of your program, this one actually compiles, but i don't know if it does what it supposed to.The main difference is that i used switch statements instead of really hard and buggy else if else, etc.
Remember! I have only modified the structure of the program, i didn't modify what it does.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include<iostream>

using namespace std;

float b=1000;

int main() // int main() not void main()
{
  //clrscr();
  float x,b,c,amount1,amount2,amount3,p;
  float d,a,o,q,r,t,u,v,w,g,h;
  int s,j; // s and j should be int not float
  int m;
  char choice;
  char l,Y,y,N,n;

  cout<<endl<<"Welcome to my grocery store!!!!";
  cout<<endl<<"Would you like to see the items available for purchase(y/n)?";
  cin>>choice;

  if(choice=='Y'||choice=='y')
  {
    cout<<"the items available are:";
    cout<<endl<<"no."<<'\t'<<"item "<<'\t'<<"quantity(b)(in grams)"<<'\t'<<"m.r.p(c)";
    cout<<endl<<"---"<<'\t'<<"---- "<<'\t'<<"---------------------"<<'\t'<<"--------";
    cout<<endl<<"1. "<<'\t'<<"urad dal "<<'\t'<<"1000g "<<'\t'<<"Rs.50.25";
    cout<<endl<<"2. "<<'\t'<<"tur dal "<<'\t'<<"1000g "<<'\t'<<"Rs.60.75";
    cout<<endl<<"3. "<<'\t'<<"tea powder "<<'\t'<<"1000g "<<'\t'<<"Rs.200.0";
    cout<<endl<<"Would you like 2 purchase any item?(y/n)";
    cin>>choice;

    if(choice=='Y'||choice=='y')
    {
    cout<<endl<<"you can purchase only two items( kindly press 'n' after purchasing two items";
    m:
    cout<<endl<<"nenter the no:of the item chosen by u";
    cin>>m;

    switch(m) // use a switch instead of multiple 'if else'
    {
      case 1:
        cout<<endl<<"enter the amount of the item u want to purchase";
        cin>>x;
        amount1=(x*50.25)/1000.00;
        cout<<endl<<"the amount to be paid is:"<<amount1<<"\n";
        break;
      case 2:
        cout<<"\nenter the amount of item ";
        cin>>x;
        amount2=(x*60.75)/1000.00;
        cout<<"\nthe amount 2 b paid is:"<<amount2<<"\n";
        break;

      case 3:
        cout<<"\nenter the amount of item";
        cin>>x;
        amount3=(x*200.00)/1000.00;
        cout<<"\nthe amount 2 be paid is:"<<amount3<<"\n";
        break;
    }

    cout<<endl<<"Do you want to buy another item?";
    cin>>l;

    if(l=='y'||l=='Y')
      goto m;
    else
      cout<<endl<<"Please wait.... your bill is being calculated....";

    cout<<endl<<"Enter the no: of the items u've bought in an order(enter 0 for the second item if u've bought only one item:";
    cin>>s>>j;

    switch(s)
    {
      case 1:
        switch(j)
        {
          case 0:
            o=amount1;
            cout<<endl<<"The total bill is:"<<o;
            break;
          case 1:
            p=amount1+amount1;
            cout<<endl<<"the total bill is:"<<p;
            break;
          case 2:
            q=amount1+amount2;
            cout<<endl<<"the total bill is:"<<q;
            break;
          case 3:
            r=amount1+amount3;
            cout<<endl<<"the total bill is:"<<r;
            break;
        }
        break;

      case 2:
        switch(j)
        {
          case 0:
            a=amount2;
            cout<<endl<<"the total bill is:"<<a;
            break;
          case 1:
            t=amount2+amount1;
            cout<<endl<<"the total bill is:"<<t;
            break;
          case 2:
            u=amount2+amount2;
            cout<<"\nthe total bill is:"<<u;
            break;
          case 3:
            v=amount2+amount3;
            cout<<"\nthe total bill is:"<<v;
            break;
        }
        break;

      case 3:
        switch(j)
        {
          case 0:
            w=amount3;
            cout<<endl<<"the total bill is:"<<w;
            break;
          case 1:
            g=amount3+amount1;
            cout<<endl<<"the total bill is:"<<g;
            break;
          case 2:
            h=amount3+amount2;
            cout<<"\nthe total bill is:"<<h;
            break;
          case 3:
            d=amount3+amount3;
            cout<<"\nthe total bill is:"<<d;
            break;
        }
      }
    }

    cout<<"\nplease pay the requested amount";
    cout<<"\nthank you.please visit again";
  }
  else if(choice=='N'||choice=='n')
    cout<<endl<<"Thanks for visiting my store !!!";

  // }  this lines where removed because thy seem to do the same thing as above and they produce
  //    a compile error
  // else if(choice=='N'||choice=='n')
  //   cout<<"\nthank you.kindly try purchasing the next time u visit the store!!!!!";

  return 0;
}
Last edited on
A beginning programmers using labels and goto??? Epic Fail teaching C++.
Epic Fail teaching C++.
haha
What's worse? Shortening one's words with acronyms (not that bad, happens all the time), or using "da" in place of "the", "dat" for "that", and "dis" for this?

Don't take it the wrong way; just trying to help grammar survive.
Last edited on
oook...i'll try correcting my grammar....and i'm totally a beginner in c++.....so this is the best i could come up with...and i really thank u all for ur "kind" views...and replies...i'll try my best to correct myself....and i'm sorry again if i offended anyone with my grammar....sry....
Topic archived. No new replies allowed.