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;
}