0

I am currently working on a simple C++ program for a beginner's programming class. The aim of this program is to have the computer output the word "Firebird" when the user inputs either a capital or a lowercase letter 'f', while making using of if/else statements. I should note that I have gotten the actual program itself to perform its intended function.

However, every time I execute it, it simply exits out of the console immediately after I input a value. The only way I have been able to actually examine the program and its results is to enter system("PAUSE") near the end of my program (very bad programming practice, I know, but it seems to be the only thing that keeps it from exiting out, and I DO NOT intend on keeping it in the final program, I simply had it there for observation purposes) to keep the console from closing.

Does anybody have any suggestions of why it might be doing this?

(P.S. If anybody has any suggestions of how my code could be improved in general, please let me know. I am a beginner and I am willing and eager to learn.)

This is my code:

#include <iostream>
#include <string>

using namespace std;

int main() {

    char animal = 'F';

    cout << "Please enter a character: ";
    cin >> animal;

    {
        if (animal == 'F')
            cout << "Firebird" << endl;
        else if (animal == 'f')
            cout << "Firebird" << endl;
        else
            cout << "Invalid Entry" << endl;
    }

    string y;
    getline(cin, y);

    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Leo Derr
  • 1
  • 1
  • Console programs (and indeed all programs) are _supposed_ to exit when they end. –  Apr 26 '17 at 00:14
  • I know that. I should have specified that this program is meant to obtain some additional input from the user before exitting, so that the output generated from the input can be viewed by the user (as in a "press enter to continue" sort of deal) – Leo Derr Apr 26 '17 at 00:17
  • Not sure what else you're looking for. You either exit, or you pause. Or you have the user enter something. But none of that seems necessary, especially if you run your program directly from the command line. Or you set a debug breakpoint. – David Makogon Apr 26 '17 at 00:18
  • As far as any other feedback - that's all opinion-soliciting. A "code review" question doesn't really fit here. – David Makogon Apr 26 '17 at 00:18

0 Answers0