Dev-C++, Only One Input...

Jan 15, 2010 at 11:09pm
Hey forum, I'm having a problem with my program. I can't seem to enter more than one command and then I'm forced to close my program. For example, when I assign a value to a variable and press enter it goes through, but then when I try to perform another action the window closes... any hot fixes?

Thanks,
Xitan
Last edited on Jan 15, 2010 at 11:13pm
Jan 15, 2010 at 11:13pm
What is your code?

- Also : Change your IDE, Dev-C++ is outdated http://www.cplusplus.com/forum/articles/7263/ -
Jan 15, 2010 at 11:15pm
Well to start I would like to tell you there isn't much help to be offered unless you submit your code for that piece of your program.
Jan 15, 2010 at 11:26pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
include <iostream>

int main()
{
    using std::cin;
    using std::cout;
    using std::endl;
    
    cout << "\nWELCOME TO COUNTER STRIKE: CMD TASK FORCE!" << endl;
    cout << "\n\nWhat would you like to do? Select one of the options below; \nenter the numberthat represents the option:\n===========================================================\n";
    
    int goption;
     
    cout 
    << "1) Start Game..." 
    << endl 
    << "2) How to Play..." 
    << endl 
    << "3) About..." 
    << endl 
    << "4) Exit." 
    << '\n';
    
    cin >> goption;
    cin.ignore();
    
    if (goption == 1) {
           cout << "You are equipped with armor and a weapon." // String continues...
            "Your team has fallen and you're the only survivng member." // String continues...
            "There are three enemys left, and how you fight will ultimately" // String continues...
            "lead to whether you're victorious or your mission was a failure." // String continues...
            "How do you want to proceed?"; // String ends.    
          
          } else { goption >= 5; }
                 
    if (goption == 2) {
           cout << "Simply enter options as you make your way through the game.";
           } else { goption >= 5; }
                  
    
    if (goption == 3) {
           cout << "Counter Strike: CMD Task Force was written by Weston Soden." 
                    "The program is a simple game that asks for the users input" 
                    "throughout the game, though it is not very complex, it is" 
                    " still very fun.";
           } else { goption >= 5; }
           
    if (goption == 4) {
                cout << "Press the \"ENTER\" key to exit:"; }
    
    if (goption <= 0) {
                cout << "Please enter a valid option."; }
    
    if (goption >= 5) {
           cout << "Plese enter a valid option."; }
           
    
                  
                  
           
           
    cin.get();
    std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
    return (0);
}


Sorry about the title, was a dumb idea i got in my head.
Last edited on Jan 15, 2010 at 11:27pm
Jan 15, 2010 at 11:32pm
What are you doing on lines 34, 38 and 46 with goption >= 5?
Last edited on Jan 15, 2010 at 11:32pm
Jan 15, 2010 at 11:34pm
For example, when I assign a value to a variable and press enter it goes through, but then when I try to perform another action the window closes...
Can you elaborate that? You are reading input only once in your program so it does what it should.
Jan 15, 2010 at 11:35pm
I know for starters you need a pound symbol (#) in front of your include at the beginning.
Jan 15, 2010 at 11:36pm
His cin.get(); command accepts a second input which puts on the illusion of another variable input and then proceeds to closing the program.
Topic archived. No new replies allowed.