Why this program works fine with bc++ but it exit just ater getting the value of x from console in vc++?
#include <iostream.h>
void main()
{
int x;
cin >> x;
// cout<<endl;
x=x-10;
cout << x;
cin.get();
}
Printable View
Why this program works fine with bc++ but it exit just ater getting the value of x from console in vc++?
#include <iostream.h>
void main()
{
int x;
cin >> x;
// cout<<endl;
x=x-10;
cout << x;
cin.get();
}
Works fine for me. Try starting it from a command prompt. You're not seeing the printout because the program closes.
Also, you're horribly non-standard there:The cin.get() at the end didn't work, so I used the method of choice for most people. Note that that will only work on DOS or DOS-compatible systems.Code:#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int x;
cin >> x;
x = x - 10;
cout << x << endl;
system("pause");
}
When you run a console program from VC++, it automatically adds its own prompt anyway.
Thank U very much. It works (waits until we hit any key in bc++) but not in vc++.
#include <iostream.h>
#include <conio.h>
void main()
{
int x;
cin >> x;
cout<<endl;
x=x-10;
cout << x;
//cin.get();
while(!kbhit());
}
You missed my second point completely. Don't use <iostream.h>. Technically you shouldn't use <conio.h> either, but...
Code:#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int x;
cin >> x;
x = x - 10;
cout << x << endl;
system("pause");
}
Huh?