Hi,
In the past few C++ examples i have worked through i have used cin.get() to wait for the enter key to be hit before the console window is closed (so code output can actually be observed before it disappears).
I was experimenting with a very simple piece of code...
Code:
#include <iostream>
using namespace std;
int mathit(int a,int b) {
int c = 5;
return (a+b)*c;
}
int main() {
int first,second;
cout << "Please enter a number... ";
cin >> first;
cout << "\n\nPlease enter another number... ";
cin >> second;
cout << "\n\nResult of function call: " << mathit(first,second);
cin.get();
}
but here the console window closes directly after the code has been processed rather then waiting for the enter key to be hit.
I tried replacing it with system("pause"); which works fine, but i don't understand why cin.get() doesn't work here... have i misunderstood how it is supposed to work... or maybe i have overlooked something obvious?