Hello, I'm learning to start to program in C++, and I have a problem with the prompt closing before the program ends. I know there's a lot of info about it, and I've googled it and searched here, but all the solutions to system("pause") don't work for me.
I'm using Dev-C++, and this is an example of a program that I tried to compile, but it closed after I input the random number.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int magic; //Magic number
int guess; //User's guess
magic = rand(); //Random number function
cout << "Enter your guess: ";
cin >> guess;
if (guess == magic) { //if guess is right
cout << "**Right**";
}
else {
cout << "...Sorry, you're wrong.\n";
cout << "The number was " << magic;
}
return 0;
}
I know it's basic, but whatever thing that I try (cin.get(), etc...), it just doesn't seem to work.
Thanks in advance