Skip to content

Instantly share code, notes, and snippets.

@gegagome
Created September 8, 2016 04:43
Show Gist options
  • Save gegagome/3427de5446a2918a433973c46dc57149 to your computer and use it in GitHub Desktop.
Save gegagome/3427de5446a2918a433973c46dc57149 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include "IceCream.h"
iceCream::iceCream() {
}
void iceCream::printIceCreamAmount() {
cout << "1 scoop\t\t\t\t$2.00" << endl;
cout << "2 scoop\t\t\t\t$3.00" << endl;
cout << "each scoop after 2\t$3.00\n" << endl;
}
void iceCream::printIceCreamFlavors() {
cout << "1 for \t\t\t\tvanilla" << endl;
cout << "2 for \t\t\t\tstrawberry" << endl;
cout << "3 for \t\t\t\tchocolate" << endl;
}
int iceCream::howMany(const int &Minlimit, const int &Maxlimit) {
int amount = 0;
cin >> amount;
while (amount < Minlimit || amount > Maxlimit) {
cout << "\nPlease enter a valid number between " << Minlimit << " and " << Maxlimit << endl;
amount = howMany(Minlimit, Maxlimit);
}
return amount;
}
double iceCream::howMuch(int &amountOfScoops) {
double price = 0;
if (amountOfScoops == 1) {
price = 2.00;
} else if ( amountOfScoops == 2) {
price = 3.00;
} else {
price = 3.00 + ((amountOfScoops - 2) * .75);
}
return price;
}
#include <iostream>
#include <string>
using namespace std;
enum iceCreamFlavors { VANILLA = 1, STRAWBERRY, CHOCOLATE };
class iceCream {
public:
iceCream();
void printIceCreamAmount();
void printIceCreamFlavors();
int howMany(const int &Minlimit, const int &Maxlimit);
double howMuch(int &);
private:
};
#include <iostream>
#include <map>
using namespace std;
#include "IceCream.h"
int main(int argc, const char * argv[]) {
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
double price = 0;
const int MAX_SCOOPS = 5;
int amountOfIceCreams = 0;
map<int, int> scoopsPerCone;
iceCreamFlavors flavors;
iceCream iceCream;
iceCream.printIceCreamAmount();
cout << "Enter number of ice creams you would like to order" << endl;
amountOfIceCreams = iceCream.howMany(0, 10);
for (int i = 0; i < amountOfIceCreams; i++) {
cout << "\nHow many scoops would you like for cone # " << i + 1 << endl;
int amountOfScoops = 0;
amountOfScoops = iceCream.howMany(1, MAX_SCOOPS);
scoopsPerCone.emplace(i, amountOfScoops);
cout << scoopsPerCone[0] << endl;
cout << "\namountOfScoops has a value of: " << amountOfScoops << endl;
for (int j = 0; j < amountOfScoops;) {
cout << "\nSelect a flavor from the list below" << endl;
iceCream.printIceCreamFlavors();
string flavor = "";
int flavorFromEnum = 0;
cin >> flavorFromEnum;
switch (flavorFromEnum) {
case VANILLA:
flavors = VANILLA;
flavor = "Vanilla";
break;
case STRAWBERRY:
flavors = STRAWBERRY;
flavor = "Strawberry";
break;
case CHOCOLATE:
flavors = CHOCOLATE;
flavor = "Chocolate";
break;
default:
break;
}
cout << "\nHow many scoops for flavor " << flavor << endl;
int scoopsOfSingleFlavor = iceCream.howMany(1, amountOfScoops - j);
j = j + scoopsOfSingleFlavor;
cout << "\nNumber of scoops ordered: " << j << endl;
}
price = price + iceCream.howMuch(amountOfScoops);
cout << "\nNumber of scoops in ice cream # " << i << " is: " << scoopsPerCone.count(0) << endl;
}
cout << "\nTotal charge is: " << price << endl;
return 0;
}
@gegagome
Copy link
Author

gegagome commented Sep 8, 2016

Enter number of ice creams you would like to order
1 scoop $2.00
2 scoop $3.00
each scoop after 2 $3.00

3

How many scoops would you like for cone # 1
4

Select a flavor from the list below
1 for vanilla
2 for strawberry
3 for chocolate
2

How many scoops for flavor Strawberry
2

Select a flavor from the list below
1 for vanilla
2 for strawberry
3 for chocolate
2

How many scoops for flavor Strawberry
2

How many scoops would you like for cone # 2
5

Select a flavor from the list below
1 for vanilla
2 for strawberry
3 for chocolate
1

How many scoops for flavor Vanilla
1

Select a flavor from the list below
1 for vanilla
2 for strawberry
3 for chocolate
2

How many scoops for flavor Strawberry
2

Select a flavor from the list below
1 for vanilla
2 for strawberry
3 for chocolate
1

How many scoops for flavor Vanilla
3

Please enter a valid number between 1 and 2
2

How many scoops would you like for cone # 3
1

Select a flavor from the list below
1 for vanilla
2 for strawberry
3 for chocolate
3

How many scoops for flavor Chocolate
1

Total charge is: 11.75
Program ended with exit code: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment