-
Notifications
You must be signed in to change notification settings - Fork 0
/
makemenu.cpp
95 lines (83 loc) · 2.11 KB
/
makemenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// MakeMenu.cpp
#include <stdexcept>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include "fooddatabase.h"
#include "menuplanner.h"
using std::cout;
using std::cin;
using std::endl;
int main()
{
try
{
srand( time(NULL) );
FoodDatabase foodsWeLike("foods.txt");
bool keepPlanning = true;
while(keepPlanning)
{
cout << endl << "How many lunches? (0-7)" << endl;
std::string lunchstr = "";
size_t numLunches;
bool lunchPrompt = true;
while (lunchPrompt)
{
getline(cin, lunchstr);
std::stringstream(lunchstr) >> numLunches;
if ( numLunches < 0 || numLunches > 7)
cout << "Input is not valid. Try again." << endl;
else
break;
}
cout << "How many dinners? (0-7)" << endl;
std::string dinnerstr = "";
size_t numDinners;
bool dinnerPrompt = true;
while (dinnerPrompt)
{
getline(cin, dinnerstr);
std::stringstream(dinnerstr) >> numDinners;
if (numDinners < 0 || numDinners > 7)
cout << "Input is not valid. Try again." << endl;
else
break;
}
MenuPlanner mymenu(foodsWeLike, "have.txt", numLunches, numDinners);
mymenu.makeMenu();
cout << "Accept this menu? (y/n)" << endl;
std::string answer = "";
bool quitPrompt = true;
while (quitPrompt)
{
std::getline(cin, answer);
// std::stringstream inputstream(answer);
if (answer != "y" && answer != "n")
cout << "That is not a valid input. Try again." << endl;
else
break;
}
if (answer == "y")
{
mymenu.printShoppingList();
mymenu.printCost();
break;
}
}
// save menu to file?
// print shopping list? (used - have)
// print what we have that's not used
// print estimated cost
}
catch (std::logic_error& exc)
{
std::cerr << "Abnormal terminal due to internal logic error" << std::endl;
std::cerr << "Details: " << exc.what() << std::endl;
}
catch (std::exception& exc)
{
std::cerr << "Abnormal termination." << std::endl;
std::cerr << "Details: " << exc.what() << std::endl;
}
}