Home › Forums › C Programming › hi….
- This topic has 8 replies, 2 voices, and was last updated 15 years, 7 months ago by GWILouisaxwzkla.
- AuthorPosts
- April 26, 2009 at 10:59 am #2191MerissaQxmParticipant
i’m new c++….and i have jus started learnin …i’m a beginnner….
so cud sum1 pls correct dis code….and suggest sum changes….so dat it calculates da bill even if da items r bought at random…?(…..coz now it only calculates da bill if da items r bought in an order…) - April 26, 2009 at 9:39 pm #3555GWILouisaxwzklaParticipant
could you post your source code?
- April 27, 2009 at 11:37 am #3556MerissaQxmParticipant
i know dis is da wrong way 2 b doin da program….but i’m jus a beginner….so dis is da best i cud think of….and i seriously need all da help dat i can get….plsssssssssssssss…..
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141#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'<<"<hr class="bbcode_rule" />"<<'t'<<"<hr class="bbcode_rule" />";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();} - April 27, 2009 at 8:51 pm #3557GWILouisaxwzklaParticipant
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……..
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485<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 /> - April 27, 2009 at 9:11 pm #3558GWILouisaxwzklaParticipant
oops. try this version with total as a double :
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889<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 />double 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 /><br /><br /><br /><br /><br /> - April 28, 2009 at 3:45 pm #3559MerissaQxmParticipant
i divide dem all wid 1000…coz….its like….I USED DA FOLLOWIN LOGIC…
for 1000g –> it costs Rs.100.00
so for xg –>it should cost Rs. (100*x)/1000
SO…must i not divide it by 1000…..? - April 28, 2009 at 10:03 pm #3560GWILouisaxwzklaParticipant
yeah , that makes sence :) .
- April 29, 2009 at 5:53 am #3561MerissaQxmParticipant
:)
so….da program WILL give me da expected result…..rite…? - April 30, 2009 at 8:39 pm #3562GWILouisaxwzklaParticipant
If your original calculations are correct it should be fine. You’ll need to test the program thought…….
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.