recipies

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>

using namespace 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!!
Hi Perry,

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

Hope this helps.

TheIdeasMan
@Perry Turner
There's an article about this that you might want to look into. Good luck! http://www.cplusplus.com/articles/4z18T05o/


@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.


-Albatross
@Albatross:

I must have my wires crossed there! It's late - I mean early, have been going all night helping out.

Maybe both Perry and I should read the documentation for the streams classes !!

Cheers TheIdeasMan

@ Albatross
Thanks, but when I try any of the ones on that article, it doesn't work.
??
@TheIdeasMan
That won't work either...
@TheIdeasMan
That won't work either...


Do you mean the clear screen part?

@ Albatross
Thanks, but when I try any of the ones on that article, it doesn't work.


Are you sure? Can you post your new code?


Or did you mean the functions that are called from the switch statement?

Cheers TheIdeasMan
Topic archived. No new replies allowed.