You nearly have it, have a read of this :
Just need to add the bool controlled while loop.
Also the code would be tidier, if each case called a function, rather than having a big long winded switch. The code which shows the menu should be in it's own function as well.
Declare the functions before main(), then place the definitions of them after main()
And avoid the
using namespace std;
- it brings the whole of the std namespace into the global one, which can cause naming conflicts - which is what we are trying avoid. Do you realise there are a number commonly used words in
std::
like
std::left
,
std::right
,
std::distance
to name just a few. So if you had a variable or function called distance, the compiler would throw out all kinds of messages, because
std::distance
means a very different thing.
So you can put
std::
before each
std
thing (a lot of people do this), or you can put these at the top of your file :
1 2 3 4
|
using std::cout;
using std::cin;
using std::endl;
using std::string;
|
Then use them without qualification after that.
Ideally, one should always put their code in a
namespace
of it's own. You can read about in the reference section top left of this page.
Hope all goes well.