Umm I created a code which will create many results with specific ints(integers).I use Code::Blocks as my compiler.The code works inside the compiler,but when I go to the saved folder and run the batch file this is what happens-I enter a number and press enter and it simply closes itself!@What's wrong?

#include <iostream>

using namespace std;

int main()
{
    int thisisanumber;

    cout<<"Give me a number: ";
    cin>>thisisanumber;
    if ( thisisanumber == 80 || thisisanumber == 13 ) {
        cout<<"How did you?!... ";
    }
    else if ( thisisanumber == 7 || thisisanumber == 11 ) {
        cout<<"Awesomeness controls you and you control awesomeness!";
    }
    else if ( thisisanumber == 9 || thisisanumber == 14 ) {
        cout<<"Pretty good!";
    }
    else if ( thisisanumber == 15 || thisisanumber == 55 ) {
        cout<<"Not bad nor good.";
    }
    else if ( thisisanumber == 22 || thisisanumber == 43 ) {
        cout<<"Average...";
    }
    else if ( thisisanumber == 43 || thisisanumber == 33 ) {
        cout<<"You need to improve the part of your brain-RANDOMNESS!";
    }
    else if ( thisisanumber == 69 || thisisanumber == 49 ) {
        cout<<"Go visit a random doctor.";
    }
    else {
        cout<<"Even the word BAD would feel ashamed to go to you!";
    }
    cin.get();
}

Reply quickly guys.

Signing off,
C++creator:

Sorry,my mistake.I forgot to put

cin.ignore();

.It is solved.Sorry.


Signing off,
C++creator

Your pause at the end isn't really pausing because there's extraneous characters in the stream. Specifically, when reading an integer, the [Enter] key you pressed will remain in the stream for cin.get() to read later. You'll find that if you call cin.get() a second time, it'll work as intended, which highlights the issue quite well.

Hey Narue,
Thanks a lot,but isn't the problem that I forgot to put

cin.ignore();

on line 11.Reply,because I'm actually just a beginner at C++.

And I learn from this site called cprogramming.com. I am on lesson 4,functions and I can't understand a word they are saying.Reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.