Advertisement
Guest User

Untitled

a guest
May 25th, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <array>
  5. #include "conio.h"
  6. using namespace std;
  7.  
  8. array<int, 12> bankovky = { 5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5, 2, 1 };
  9. array<int, 12> pocet;
  10. array<int, 12> vycetka(int castka, array<int, 12> bankovky);
  11.  
  12. int main(void)
  13. {
  14.     cout << "Castka: ";
  15.     string castka;
  16.  
  17.     try {
  18.         cin >> castka;
  19.     } catch (int e) {
  20.         return 0;
  21.     }
  22.  
  23.     cout << endl << "Vysledek: " << endl;
  24.  
  25.     pocet = vycetka (atoi (castka.c_str()), bankovky);
  26.  
  27.     for (int i = 0; i < pocet.size(); i++)
  28.     {
  29.         if (pocet[i] != 0)
  30.             cout << pocet[i] << "x " << bankovky[i] << " Kc" << endl;
  31.     }
  32.  
  33.     _getch();
  34.     return 0;
  35. }
  36.  
  37. array<int, 12> vycetka(int castka, array<int, 12> bankovky)
  38. {
  39.     array<int, 12> pocet;
  40.  
  41.     for (int i = 0; i < bankovky.size(); i++)
  42.     {
  43.         pocet[i] = castka / bankovky[i];
  44.         castka = castka % bankovky[i];
  45.     }
  46.  
  47.     return pocet;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement