I just downloaded Dev-C++ and tried typing code. My first test was
#include <iostream>
using namespace std;
int main()
{
cout << "Enter height in centimeters: ";
int centimeters;
cin >> centimeters;
cout << "Your height in feet " << centimeters << endl;
return 0;
}
But I have discovered that no matter what code I use, if I have the line "cout << "Your height in feet " << centimeters << endl;" then if I press the enter(return) key my program window closes. Can someone please tell me why? Thanks
It is working as expected. You created a simple console that operates on a command line. When a console application is loaded by double-clicking or otherwise running it from the GUI, Windows creates a temporary console, executes the program, and then closes the console when you press a key after the code has finished executing.
If you want the console to stay open after the program has executed so you can execute other programs, click "Start", click "Run...", type "cmd", click "OK", change the path to the folder where your program is located, and then execute the program.
>cin.ignore(numeric_limits<streamsize>::max(), '\n');
If you're going to use this solution, you need to include <limits> to get access to std::numeric_limits<>.
thx for the help. my program will atleast let me press enter and then show me answer to my question, but closes if i press enter again. is there an easy way to loop it so that after it shows answer it starts question again so you can try a different number without closing the window? thx
ok, your advice was much appreciated I've now tried to create a calculator that tells you how many days have passed since year 0000, but am having a bit of trouble. can someone please help thx
also, i'm probably writing more code than i should be, any shortcuts would be very nice too
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.