[C++] Need Help Making Menu Program

This is a discussion on [C++] Need Help Making Menu Program within the C++ Programming forums, part of the General Programming Boards category; Hi all, I need some help making a menu program that will, when I enter a certain number, open the ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    2

    [C++] Need Help Making Menu Program

    Hi all,

    I need some help making a menu program that will, when I enter a certain number, open the program assigned to it. For example if I type the number 1 and hit Enter, then it'll open the program Example.exe which is in the same folder as the menu program.

    I've tried making it already, but it didn't open the program. It just gave the program a size of 0 KB (I looked in the map that Example.exe is in and saw that at the ofstream command it made the file 0 KB and let it become useless (luckily I had it backed up, so no worries about that).

    Here's the code I used for that:
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        int Difficulity;
    
        cout << "This is a program to choose between the difficulities created" << endl;
        cout << "for my ApplePuzzle program" << endl;
        cout << "Untill now, you can only choose Easy (type 1 for that)" << endl;
        cin >> Difficulity;
        cin.ignore();
    
        switch ( Difficulity ) {
            case 1:
                ofstream a_file ( "ApplePuzzle Easy v1,1.exe" );
                return 0;
        }
        return 0;
    }
    Also I'd like to know how to get it to do something else when I put in something different than 1.

    I really hope someone can help me.

    Code:
    #include iostream
    
    using namespace std;
    
    int main() {
    
    int UseFullComments;
    
    if ( UseFullComments > 0 ) { 
            cout << "Bartvo is Happy" << endl;
    }
    else {
            cout << "Bartvo isn't Happy..." << endl;
    }
    cin.get()
    return 0;
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    ofstream is for outputting data into a file, which is why it truncated Example.exe.

    You probably want to use the system() command.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    2
    Quote Originally Posted by MK27 View Post
    ofstream is for outputting data into a file, which is why it truncated Example.exe.

    You probably want to use the system() command.
    Thanks for the reply.

    So if I'd use the system() command it would look something like this?:
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        int Difficulity;
    
        cout << "This is a program to choose between the difficulities created" << endl;
        cout << "for my ApplePuzzle program" << endl;
        cout << "Untill now, you can only choose Easy (type 1 for that)" << endl;
        cin >> Difficulity;
        cin.ignore();
    
        switch ( Difficulity ) {
            case 1:
                system ( "ApplePuzzle Easy v1,1.exe" );
                return 0;
        }
        return 0;
    }
    EDIT: I got it working now using the system() command, though I did have to change the excecutable's name. It doesn't accept spaces and commas. Thanks for the help MK27.
    Last edited by Bartvo; 03-10-2010 at 09:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Replies: 2
    Last Post: 01-21-2008, 01:07 AM
  3. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  4. Menu stuff
    By Shadow in forum C Programming
    Replies: 10
    Last Post: 04-28-2002, 09:05 AM
  5. C menu driven program
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 08:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21