Home › Forums › C Programming › hi…. › Re: Re: hi….
April 27, 2009 at 8:51 pm
#3557
GWILouisaxwzkla
Participant
heres a start ( I’m not certain why you are dividing every purchase in the program by 1000 ) . By the way don’t use “gotos” in high level programming languages , this is considered bad programming practice ( google Dijkstra ). Anyway , this is how I might code what you have ( the total comes out 0 since everything is divided by 1000 ). Anyway……..
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 | <br /> <br /> #include<iostream.h><br /> #include<conio.h><br /> #include <ctype.h><br /> <br /> float b=1000;<br /> void main()<br /> {<br /> //clrscr();<br /> <br /> int total = 0;<br /> double amount;<br /> double temp;<br /> char choice;<br /> cout << "nwelcome 2 my grocery store!!!!";<br /> cout << "nwould u like 2 see the items available for purchase(y/n)? ";<br /> cin >> choice;<br /> cin.get();<br /> if ( choice == 'Y' || choice == 'y' )<br /> {<br /> <br /> do<br /> {<br /> <br /> cout << "the items available are:";<br /> cout << "nno."<<'t'<<"item "<<'t'<<"quantity(b)(in grams)"<<'t'<<"m.r.p(c)";<br /> cout << "n---"<<'t'<<"---- "<<'t'<<" <hr class="bbcode_rule" /> "<<'t'<<" <hr class="bbcode_rule" /> ";<br /> cout << "n1. "<<'t'<<"urad dal "<<'t'<<"1000g "<<'t'<<"Rs.50.25";<br /> cout << "n2. "<<'t'<<"tur dal "<<'t'<<"1000g "<<'t'<<"Rs.60.75";<br /> cout << "n3. "<<'t'<<"tea powder "<<'t'<<"1000g "<<'t'<<"Rs.200.0";<br /> cout << "n enter choice => ";<br /> cin >> choice;<br /> cin.get();<br /> <br /> <br /> if( choice == '1' )<br /> {<br /> cout << "nenter the amount of the item u want to purchase ";<br /> cin >> amount;<br /> temp = ( amount * 50.25 ) / 1000.00;<br /> total = temp + total;<br /> cout << "n the amount to be paid is:" << temp << "n";<br /> }<br /> else if( choice == '2' )<br /> {<br /> cout << "nenter the amount of item ";<br /> cin >> amount;<br /> temp = ( amount * 60.75 ) / 1000.00;<br /> total = temp + total;<br /> cout << "nthe amount 2 b paid is:" << total << "n";<br /> }<br /> else if( choice == '3' )<br /> {<br /> cout << "nenter the amount of item ";<br /> cin >> amount;<br /> temp = ( amount * 200.00 ) / 1000.00;<br /> total = temp + total;<br /> cout << "nthe amount 2 be paid is:" << total << "n";<br /> }<br /> cout << "ndo u want to buy another item? ";<br /> cin >> choice;<br /> cin.get();<br /> } while ( choice == 'y' || choice == 'Y' );<br /> <br /> cout<<"nplease wait.... ur bill is being calculated...." << endl;<br /> cout << "the total is " << total << endl;<br /> <br /> <br /> cout << "nplease pay the requested amount" << endl;<br /> cout << "nthank you.please visit again" << endl;<br /> <br /> cout<<"nthanks for visiting my store !!!" << endl;<br /> <br /> }<br /> cout << "nthank you.kindly try purchasing the next time u visit the store!!!!!" << endl;<br /> <br /> getch();<br /> }<br /> <br /> |