for (int i = 0; i < no_students; i++)
{
int studentmoney, no_bottles, Change;
cin >> studentmoney >> no_bottles;
int count50=0;
int count100=0;
int count200=0;
Put your initial counts OUTSIDE the for loop.
You're just starting from zero each time.
And just learn to put debug cout statements through your code if you're in any way confused as to what's going on.
Say
So I managed to count the each type of coins in the studentmoney
But also I want to count the each type of coins in the machinemoney
Please help this has been so hard for me
I managed to count the each type of coins in the studentmoney
No, you're counting the number of each coin in the machine. Lines 22 -33 basically take the student's coin (studentMoney) and place it into the appropriate bin the machine.
I suggest that you add comments to the variables stating exactly what they mean. For example:
1 2 3 4 5 6 7 8
int no_students; // The number of transactions
cin >> no_students;
int machinemoney = 0; // Total amount of money in the machine
bool okay = true; // Can the machine provide change so far?
int count50=0; // Number of 50-cent coins in the machine
int count100=0; // Number of 100-cent coins in the machine
int count200=0; // Number of 200-cent coins in the machine
Now you need to add the logic to see if you can actually make change. I'd put that in a function if you've learned about them.
And yes i know that I'm counting each type of coins in the machine
But when change is given I need to update the count to substract the change given
Example
When user inputs
50 1
50 1
50 1
50 1
200 1
100 1
100 1
Here the machine will have four 50coins, one 200 coins and one 100coins
The change given to the fifth customer is 150 which is (three 50 coins)
Which makes the machine to have (one 50 coin, one 200coin) in it.
Then the sixth customer needs change of 50 which will make the count of 50 coins in machine be zero.
Now here is the part which I'm struggling to count the remain coins after change is given.
Then the last customer needs change of 50 of which the machine has only (one 100 coin and one 200coin)
Which it will be impossible to give change
Thus it should print No
3. You should compare the counts largest to smallest, not smallest to largest.
When giving change, you always give the largest suitable coin available.
4. You need an if / else if / else chain so that you only give out ONE coin per iteration of the loop.
5. The while (Change > 0) should be inside the else if (machinemoney - Change >= 0) part of the code.
BUT!!!!
You need to make sure you can give ALL the change before you decide to give any of the change.
Simply having the numerical amount of money in the machine doesn't immediately mean you're able to give the required change.
'Bro' Salem ain't going to do diddly squat for you until you show some nouse and show that you're actually learning something.
Reposting other peoples code with broken edits (and nagging) won't get you very far here, and it won't get you far anywhere else either.
My sense is you've been coasting through the course for far too long on the back of other peoples work and "googled" answers. So much so, you're now completely hopeless at actually achieving anything new for yourself.
In short, you're wasting everyone's time - including your own.
Okay I did what you told me to do
But the place when u said that I need an if else chain so that I can give out one coin per literation I didn't understand