Auch wenn einwenig verspätet, aber ich habe mich auch mal drangesetzt, ist eher eine einfache simple Version, aber tja nu halt 20 minuten Produkt
#include<iostream>
#include<string>
using namespace std;
class iceshop {
public:
iceshop();
double get_money() const;
void set_money( double );
void action();
private:
double money;
double capri;
double nogger;
double cornetto;
int ammount;
bool pay( int );
};
iceshop::iceshop() {
money = 10.00;
capri = 1.50;
nogger = 1.80;
cornetto = 2.50;
ammount = 0;
cout << "Willkommen in Lucis Eis laden!" << endl;
cout << "Zur Zeit haben wir im Angebot: Capri für " << capri << "€, Nogger für " << nogger << "€ und Cornetto für " << cornetto << "€." << endl;
}
double iceshop::get_money() const {
return money;
}
void iceshop::set_money( double new_money ) {
money = new_money;
}
bool iceshop::pay( int choic ) {
double money_buf;
switch( choic ) {
case 1:
if( get_money() >= capri ) {
cout << "Ein Capri gekauft" << endl;
set_money( get_money() - capri );
cout << "Du hast noch " << get_money() << "€" << endl;
}else {
cout << "Nicht genügend Geld" << endl;
}
return true;
break;
case 2:
if( get_money() >= nogger ) {
cout << "Ein Nogger gekauft" << endl;
set_money( get_money() - nogger );
cout << "Du hast noch " << get_money() << "€" << endl;
}else {
cout << "Nicht genügend Geld" << endl;
}
return true;
break;
case 3:
if( get_money() >= cornetto ) {
cout << "Ein Cornetto gekauft" << endl;
cout << "Du hast noch " << get_money() << "€" << endl;
set_money( get_money() - cornetto );
cout << "Du hast noch " << get_money() << "€" << endl;
}else {
cout << "Nicht genügend Geld" << endl;
}
return true;
break;
case 4:
cout << "Good Bye" << endl << "Hier dein Rückgeld " << get_money() << "€" << endl;
break;
default:
cout << "Falsche Eingabe" << endl;
return true;
break;
}
}
void iceshop::action() {
int choic = 0;
while( true ) {
cout << "Bitte wähle: (1)Capri, (2)Nogger, (3)Cornetto, (4)Rückgeld anfordern" << endl;
cout << "Wahl:";
cin >> choic;
if( pay( choic ) == false ) {
break;
}
}
}
int main() {
iceshop Luci;
cout << "Du hast " << Luci.get_money() << "€ zur Verfügung" << endl;
Luci.action();
return 0;
}