0

What loop can I use given change for the total or need more change?

Here is my code it doesn't show the rest calculation when I put value after need more change it doesn't give the remaining change For (int m=0;m<total;m++){ If( cash<total) { Cout<<"Need more change" <<endl; Cout<<"Change received " <<endl; For(int c=0;c<cash;c++){ if (total>cash) { Cin >>cash; } } Cout <<"change give" <<endl; } } Cout<<"change" <<endl<<cash-total<<endl;

20th Nov 2019, 12:32 PM
Shofi Uddin
11 Answers
+ 1
Without full code, it is tough to understand what you said. This code saying in first for loop you are adding to price to total if itemcode and barcode same. After that you want to exit condition.? For that you can add like char c; cin>>c; if(c=='f') return; //or break; if you want come out of loop; After that You are taking input for to withdraw, if cash < total deduct from total else print msg last one and break the loop...
20th Nov 2019, 7:24 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Sentence properly or try use google translate if it is hard for you. Not understandable it is for me.. And you are not using any function any where.. Am not telling you to do anything, You tell me what is your required inputs and output.. What problem you are geeting?
20th Nov 2019, 7:46 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Shofi Uddin cout<<"the total price is"<<total<<endl; do { cout<<"cash please:"<<endl; cin>>cash; if(cash>=total) { rest=cash-total; break; } else { cout<<"you need more cash"<<endl; } }while(true); this loop works until you give needed total.. is it what you want?
20th Nov 2019, 8:04 PM
Jayakrishna šŸ‡®šŸ‡³
0
Where are you adding cash? What you are expecting by this code actually? Can you explain..
20th Nov 2019, 1:24 PM
Jayakrishna šŸ‡®šŸ‡³
0
for (int i=0;number;i++){ for (int j=0;j<5;j++){ if(itemcode[i]==barcode[j]){ total+=price[j]; } } } //here will shows the price of the totall of the user put the code // //how do i do if the user put "f" to terminate the operation the show the total value of it ..// cout <<"the total price is:" <<total<<"dollar"<<endl; cout <<"cash"; cin >>cash ; for(int m=0;m< total;m++){ if(cash>=total){ cout <<"need more money"<<endl; } } //if i need more money do i need to use others loop function..this the loop function to use if cash give less the total will show the message need more money// cout <<"change"<< cash- total <<"\n\n";
20th Nov 2019, 2:10 PM
Shofi Uddin
0
What do if mean exit conditions how do I do Because I did for loop to total the amount
20th Nov 2019, 7:29 PM
Shofi Uddin
0
Read again... And what you need exactly? What is your doubt? Did you get your answer?
20th Nov 2019, 7:35 PM
Jayakrishna šŸ‡®šŸ‡³
0
How to exit for I loop what are said is on my first loop I need to add char function
20th Nov 2019, 7:38 PM
Shofi Uddin
0
The problem I am getting is from the total I get the rest Example if the total is 40 and the user put 50 the give the rest 10 But what I want is if the total is 40 And the users put 30 will get a message need for money and the users can put more until is get the total
20th Nov 2019, 7:52 PM
Shofi Uddin
0
Yes thank you but u know u did rest=cash-total Rest do I need to declare as double Because I already declare cash and total
20th Nov 2019, 8:24 PM
Shofi Uddin
0
Rest is the remaining amount you need to give back to the user. So if you want your program to tell that and to update , then use it other wise use like cash=cash-total ; Use it according to your requirement. I cant say because i don't know about your full code. How can i say?
20th Nov 2019, 8:36 PM
Jayakrishna šŸ‡®šŸ‡³