HELP LOOP!!!

Write your question here.
I have no idea how to get the subtotal with the loop. This is still not Finish btw

Cashier 2.0 is a C++ program that displays on the screen item codes with corresponding item description and price (at least 10 items). It asks the user to enter the code of the item purchased by the customer. If the user enters a code that is not in the choices, it asks again until he/she enters a valid code. Then, its description and price are displayed on the screen. Also, it asks for the quantity of the particular item code entered. Again, if the user enters a zero or negative value, it asks again for the quantity until he or she enters a valid value. Afterwards, it displays the subtotal amount. It will keep on asking for an item code, and will process the same until such time that the user enters ‘0’. When the user enters ‘0’, the total amount due is displayed. Then, it asks the user to tender the amount of cash of the customer. If the amount tendered is less than the amount due, it asks again for the amount until he or she enters a valid amount. Then, it prints the change due to the customer. Finally, it asks the user if the user wants to process more transactions.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091`` `````` #include #include int main() { char repsonse ='Y'; double price,subtotal,subt,total; int code,quantity,response; cout<<"=========Welcome to Market========"<=101||code<=105) { cout<<"\nEnter Code:"; cin>>code; if((code<101&&code>0)||(code>105)) {cout<<"Invalid Code!"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<
Last edited on
...whitespace is your friend. That is one of the beauties of C++. You can put in as much whitespace as you want (assuming in non-string cases here) with no repercussions, compared to whitespace-dependent languages. It won't affect the end result of the code, but at least it'll be legible... next time when you go to look at your code, be a bit less stringent on your uses of the tab (which should be default 4 spaces, simply because it looks better that way) and enter key. It'll help you spot errors more easily when all of your code isn't crammed into eye-gouging boxes.

As for your actual issue... well, for one, I recommend using a switch statement, simply because long changes of if-else statements with integers looks messy in comparison to a nice, concise switch statement. About loops... I recommend that you take a look at the documentation on this site, which explains the beauty of the while loop. In several cases here, while loops would be ideal. Hell, just setting up a function for calculating the subtotal would be a good idea. That, compared to re-stating it each time. However, that's a bit beyond this program, so for now, just look at the documentation. You should also find some info on those aforementioned switches.
Made some changes to your program. Cleaned up some unnecessary statements. Also made it easier through switches incase you have yet to use switch statements.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108`` ``````#include #include using namespace std; int main() { char response; double price,subt; int code,quantity; cout<<"Do you have a customer (Y/N)"; cin>>response; while(response=='y || response == 'Y') { cout<<"=========Welcome to Market========"<>code; switch(code)//the () tells what variable to use and the case are what value will cause that to occur. { case 101: cout<<"Apple 20.00"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity;} price=20.00; subt=(quantity*price); cout<<"\$"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity;} price=25.25; subt=(quantity*price); cout<<"\$"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity;} price=30.00; subt=(quantity*price); cout<<"\$"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity; } price=35.25; subt=(quantity*price); cout<<"\$"<>quantity; if(quantity<=0) {cout<<"Invalid Quantity"<>quantity;} price=30.00; subt=(quantity*price); cout<<"\$"<>response; } ``````

if you want to make the quantity keep looping till the cashier enters in a acceptable quantity you can nest a while loop in the quantity statement

which would look like
 ``1234567891011`` ``````case 105: cout<<"Mango 30.00"<>quantity; while(quantity<=0) {cout<<"Invalid Quantity Please Enter In Valid Quantity 1+"<>quantity;} price=30.00; subt=(quantity*price); cout<<"\$"<

if you want a cash tendered portion I will give you a quick skeleton.
you would need two variables added. And this would be inserted into the case 0: portion since that is your sentinal value and values are isolated to the loop/function they are part of.

 ``12345678`` ``````output "please enter in amount tendered." input tender while((tender-total)<0) output "Invalid Amount Tendered please Pay Proper Amount" change = tender-total output change ``````

But with all the things you want this program to do you should also learn about classes or function to also help make your program easier to follow.
Last edited on
this works. lack of comments in the source code, but at least it studies a little.
should be fully responsive to the track that you provide. I am allowed to add the number of daily sales and daily receipts of the sale.
I lost a bit of time to do some embroidery.
I wanted to post it the other day but I had problems with the internet. I took the opportunity to do some testing.

excuse to text messages in Italian

bye

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233`` `````` #include using namespace std; float totale, totalDay, subTotale; int numCodice=0; bool test=true; int numSale=0; void startScreen() { cout<<"+------------------------------------------------------------------------+"<<'\n'; cout<<"| company: PUSHER FRUIT 2013 |"<<'\n'; cout<<"+------------------------------------------------------------------------+"<<'\n'; cout<<"| COD: 1 = Orange; | COD: 2 = Apple; | COD: 3 = Uva; | COD: 4 = Angurie; |"<<'\n'; cout<<"+------------------------------------------------------------------------+"<<'\n'; cout<<"| COD: 0 = end Sum; | COD: 9 = Exit; |"<<'\n'; cout<<"+------------------------------------------------------------------------+"<<'\n'; } void miniscreen() { cout<<"+------------------------------------------------------------------------+"<<'\n'; cout<<"| COD: 1 = Orange; | COD: 2 = Apple; | COD: 3 = Uva; | COD: 4 = Angurie; |"<<'\n'; cout<<"+------------------------------------------------------------------------+"<<'\n'; cout<<"| COD: 0 = end Sum; | COD: 9 = Exit; |"<<'\n'; cout<<"+------------------------------------------------------------------------+"<<'\n'; } float calcTotal(float cUnit) { float quantita =0; cout<<" ********** input weigth: "<<'\n'; cin>>quantita; subTotale = quantita * cUnit; totale+=subTotale; totalDay+=totale; cout<<" ### totale per prodotto= "< 0)&&(n_Codice<=4))) { calcTotal(costoUnitario); cout<<"+-------------------------+"<<'\n'; cout<<"| input code product: |"<<'\n'; cout<<"+-------------------------+"<<'\n'; cin>>n_Codice; if (n_Codice=='9') numCodice=n_Codice; } else test=false; } return totalDay; } int monetaResto() { float resto=0; int modPay=0; float contanti=0,subSaldo=0; if (totale>0) { cout<<"+----------------------------------+"<<'\n'; cout<<"| totale dovuto: "<>modPay; switch(modPay) { case 2: { cout<<" inserisci somma versata: "<<'\n'; cin>>contanti; resto = contanti - totale; cout<<" resto euro: "<>contanti; subSaldo = totale - contanti; cout<<" saldo da versare tramite bancomat: "<0) { cout<<"+-----------------------+"<<'\n'; cout<<"| inserire PagoBancomat |"<<'\n'; cout<<"| inserire PIN code: |"<<'\n'; cout<<"| ....wait pls..... |"<<'\n'; cout<<"| transazione conclusa |"<<'\n'; cout<<"+-----------------------+"<<'\n'; numSale++; cout<<" ticket n°: 00"<>contanti; resto = contanti - totale; cout<<" resto euro: "<>numCodice; if (numCodice=='9') break; prodotto(numCodice); miniscreen(); } if (numCodice =='9') break; monetaResto(); cout<<" continue with sales? (1 = yes, 0 = not) "; cin>>otherSales; if (otherSales == 1) { test=true; totale=0; } else test=false; } cout<<"+-------------------------------+"<<'\n'; cout<<"| dayli receipts: euro | "<

ps-there are only cases impossible in reality, for example, if you pay in cash, of course, the cash will always be greater than the cost of the fruit (otherwise the fruit, do not deliver the goods);)))

Last edited on
Topic archived. No new replies allowed.