Finding left over

How do I find leftover for anything ? In my example I have 26 trashes. Each container can fill up to 5. So how do I find that there is 1 left ? I think that I should get the number 25 and then just subtract from the full amount ? 26 - 25 ?

EDIT = Apparently my do while loop includes 1 for some reason. The way I'm trying to get the leftover is by :
leftOver = trash;


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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>

using namespace std;

void readFile(int &users, int& capacity, int& trash)
{
  ifstream in("duomenys.txt");

  in >> users >> capacity >> trash;

  in.close();
}
void containersNeeded(int users, int capacity, int trash,
                      double& howMuchBins, int& binsNeeded, int& leftOver)
{
  howMuchBins = double(trash) / capacity;
  do
  {
    trash -= capacity;
    binsNeeded++;
    cout << trash << " ";
  }
  while(trash - capacity > 0);
  leftOver = trash;
}
void printAnswer(double howMuchBins, int binsNeeded, int leftOver)
{
  ofstream out("rezultatai.txt");

  out << "You will need: " << ceil(howMuchBins)
  << " in total to fill the trash." << endl;
  out << "In total there's going to be: " << binsNeeded
  << " full filled bins" << endl;
  out << "There is " << leftOver
  << " trash that's going to different container" << endl;

  out.close();
  system("start rezultatai.txt");
}

int main()
{
    int users, capacity, trash, binsNeeded = 0, leftOver = 0;
    double howMuchBins = 0;
    readFile(users, capacity, trash);
    containersNeeded(users, capacity, trash, howMuchBins, binsNeeded, leftOver);
    printAnswer(howMuchBins, binsNeeded, leftOver);
    return 0;
}
Last edited on
Never mind found the way but not sure if it's logical to use this code for looking leftovers.

1
2
3
4
5
6
7
  do
  {
    trash -= capacity;
    binsNeeded++;
    if(trash - capacity < 0) leftOver = trash;
  }
  while(trash - capacity > 0);
Topic archived. No new replies allowed.