954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Best way to do this..?

Hey, I got bored so decided to make this pointless program but am a bit confuzzled..

#include <iostream>

using namespace std;

int main()
{
    int decision;
    
    do
    {
        system("cls");
        
        cout << "Welcome to my pointless menu!" << endl;
        cout << "1 : Do Nothing." << endl << "2 : View Authors Details." << endl;
        cout << "3 : Quit" << endl << endl;
    
        cout << "Choose Your Decision : ";
        cin >> decision;
    }
    
    while( decision == 1 || decision < 1 || decision > 3 );
    
    switch( decision )
    {
            case 2:
                 system("cls");
                 
                 cout << "NAME : CRAIG AYRE" << endl;
                 cout << "SEX  : MALE" << endl;
                 cout << "AGE  : 14" << endl << endl;
                 
                 cout << "1 : Do Nothing." << endl << "2 : Return To Main Menu";
                 cout << endl << "3 : Quit";
                 
                 cout << "Choose Your Decision : ";
                 cin >> decision;
                 
                 cin.get();
                 
                 break;
                 
            case 3:
                 { }
                 
                 break;
    }
    
     do
    {
        system("cls");
        
        cout << "Welcome to my pointless menu!" << endl;
        cout << "1 : Do Nothing." << endl << "2 : View Authors Details." << endl;
        cout << "3 : Quit" << endl << endl;
    
        cout << "Choose Your Decision : ";
        cin >> decision;
    }
    
    while( decision == 2 );
    
    cin.get();
    
    return 0;
}


I've got the basic idea just I just thought, If I kept doing it i would have unlimited do loops, because the user could go view authors details go main menu.. go authors details.. etc etc.. please help :D

Black Magic
Junior Poster
178 posts since Apr 2008
Reputation Points: 25
Solved Threads: 4
 

Put the switch case inside do while

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

Why dont you put one do while loop that will stop if the user decides to exit the program. In this loop, you can use the switch statements to move through the choices.

joshmo
Posting Whiz in Training
280 posts since Oct 2007
Reputation Points: 19
Solved Threads: 20
 

Because of lack of what to do too :)..I decided to modify the code you posted. Dont know if this is what you had in mind but it works according to your requirements

#include <iostream>

using namespace std;

int main()
{
    int decision;
    cout << "Welcome to my pointless menu!" << endl;
    cout << "1 : Do Nothing." << endl << "2 : View Authors Details." << endl;
	cout << "3 : Quit" << endl << endl;
    cout << "Choose Your Decision : ";
    
	cin >> decision;
	cout<<endl;


    do
    {
        system("cls");
       

		switch( decision )
		{
			case 1:
				system("cls");

				cout << "1 : Do Nothing." << endl << "2 : Return To Main Menu";
                 cout << endl << "3 : Quit"<<endl;
                 cout << "Choose Your Decision : ";
                 cin >> decision;
                 
                 cin.get();
			break;
			
			case 2:
                 system("cls");
                 
                 cout << "NAME : CRAIG AYRE" << endl;
                 cout << "SEX  : MALE" << endl;
                 cout << "AGE  : 14" << endl << endl;
                 
                 cout << "1 : Do Nothing." << endl << "2 : Return To Main Menu";
                 cout << endl << "3 : Quit"<<endl;
                 
                 cout << "Choose Your Decision : ";
                 cin >> decision;
                 
                 cin.get();     
			break;
                 
            case 3:
                 exit(-1);
			break;

			default: cout<<"Wrong selection!"<<endl;
		}
    }while(decision!='3');
    
    return 0;
}


[EDIT] This code was not indented properly by the OP and even if i have nothing to do at the moment, Iam too lazy to format it :)

joshmo
Posting Whiz in Training
280 posts since Oct 2007
Reputation Points: 19
Solved Threads: 20
 

Ya thats what I was taking about & it would be better if lines 9 to 15 get inside do while loop.

And perhaps every case needs a do while!!

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

This is what you do when your bored ?!
I suggest you try learning the Win32 API to be able to make proper window applications, and then mabey move on to MFC when you get the hang of that. From there you should be able to make basic games / animation. Anything is more fun than this ^.^

Start with this tutorial
http://www.winprog.org/tutorial/

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

> Anything is more fun than this ^.^
Everyone has a different idea of what's fun. For example, Edward is bored to tears when forced to write "proper window applications" in C++. ;) The nice thing about C++ is that we can all do our own thing and still have a blast.

Radical Edward
Posting Pro
545 posts since May 2008
Reputation Points: 361
Solved Threads: 97
 

Ok, but I get the feeling he would be more interested in using graphics considering we are very similar ages (14-15) and seems to enjoy messing around and making games, quite like me :P . I especially think he would enjoy directX if he were a little more experienced in programming, even though it might be abit advanced for him (im also having a bit of a hard time learning it). But like you sead Everyone has a different idea of what's fun, so I might be completely wrong :icon_cheesygrin:

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

This is what you do when your bored ?! I suggest you try learning the Win32 API to be able to make proper window applications, and then mabey move on to MFC when you get the hang of that. From there you should be able to make basic games / animation. Anything is more fun than this ^.^

Start with this tutorial http://www.winprog.org/tutorial/

After 3 quarters of java I amtired of dealing with GUI's. There's just no way I can will myself to do it in C++ for any reason other than to learn the syntax involved with C-GUI's.

Alex Edwards
Posting Shark
972 posts since Jun 2008
Reputation Points: 392
Solved Threads: 109
 
so I might be completely wrong

You are not completely wrong:). Cause I like it!!! I'll give you a rep just for that link

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You