Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Created March 26, 2019 17:07
Show Gist options
  • Save nathan130200/f53dcc90be5065af3824d9975c50256c to your computer and use it in GitHub Desktop.
Save nathan130200/f53dcc90be5065af3824d9975c50256c to your computer and use it in GitHub Desktop.
Contagem de valor.
#include <iostream>
#include <cstdio>
#include <filesystem>
using namespace std;
enum MoneyType {
Moeda,
Nota
};
typedef struct _money_ {
MoneyType tipo;
double valor;
int quantidade;
} money_t;
money_t m50 = { MoneyType::Moeda, 0.50, 5 };
money_t m100 = { MoneyType::Moeda, 1.00, 5 };
char* GetTipo(MoneyType);
int main(int argc, char* argv[])
{
auto* list = new std::list<money_t>();
list->push_back(m50);
list->push_back(m100);
for (auto it = list->begin(); it != list->end(); it++)
{
auto tipo = GetTipo(it->tipo);
std::cout << tipo << " de R$ " << it->valor << ", quantidade " << it->quantidade << ", total acumulado: R$ " << it->valor * it->quantidade << endl;
}
std::system("pause");
}
char* GetTipo(MoneyType type) {
if (type == MoneyType::Moeda)
return (char*) "Moeda";
else
return (char*) "Nota";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment