MezData-Logo Lösungen Button :PI-BASIS: Lösung Wechselautomat

int wert[] = {1,2,5,10,20,50,100,200}; // Array mit den Wertangaben der Schächte
string name[] = {"1 Cent","2 Cent","5 Cent","10 Cent","20 Cent","50 Cent","1 Euro","2 Euro"};
int rest, muenzen,i; 
Eingabe rest; 
i = 7; 
while (rest>0){
  muenzen = rest / wert[i];
  if (muenzen>0){
    Ausgabe muenzen +" * "+name[i]+"\n";
  }
  rest = rest % wert[i];
  i--;
)

 C-Lösung

#include <conio.h>
#include <iostream.h>

void main(){
  int wert[] = {1,2,5,10,20,50,100,200}; // Array mit den Wertangaben der Schächte
  string name[] = {"1 Cent","2 Cent","5 Cent","10 Cent","20 Cent","50 Cent","1 Euro","2 Euro"};
  int rest, muenzen,i; 
  cin >> rest;
  i = 7;
  while (rest>0){
    muenzen = rest / wert[i];
    if (muenzen>0){
      cout << muenzen << " * " << name[i] << "\n";
    }
    rest = rest % wert[i];
    i--;
  }
  getch();
}