I'm trying to make a small cook book for myself, and I'm using a switch case, but I want the selection options to go away when the recipe comes up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main()
{
int sel;
cout << "1.Popovers\n";
cin >> sel;
switch (sel){
case 1: cout << "1 cup whole milk\n1 cup AP flour\n1 1/2 tsp kosher salt\n2 large eggs\n1 tbs. unsalted butter\n\nPreheat oven to 400 deg. oven\nBlend all ingredients\nPour resulting batter int cups of a buttered muffin tin\nPut into preheated oven for 40 min\nWhen done, take out and poke a whole in each one\nEnjoy!!";
break;
default: cout << "bad input, terminating";
break;
};
return 0;
}
I'm going to put in more things later, I just did this though.
Thank you in advance!!
One thing to do that will make the code easier to read, is to put all the cout statements for a particular recipe in a function that is called when case 1: is encountered. Obivously if you had more recipes then you would add functions to print these as well.
This will organise the the code in a much neater fashion.
Also, when you ask for input, always check that it is valid before proceeding.
You can use cout.clear to clear the screen before printing the recipe.
Look up some of my other posts about the use of std::cout
@TheIdeasMan
Careful, there. The clear() function in std::cout (and all std::ios derivatives including std::cin, std::ofstream, and std::ifstream) resets error flags. It doesn't remove data that has been output so far.