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;
}
|