Hey guys, I am starting C++ and am having a small problem. I know it is somthing simple but can't figure out what. The program closes out after you enter the width instead of displaying the area.
heres the code:
Also I am using Bloodshed C++ Beta 5. I would like to use the previous full version so that I know there are no bugs in the compiler. If any one could point me to it I would be thankfullCode:#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int length, width; cout<<"Enter the length of the object:"; cin>>length; cout<<"Enter the width of the object:"; cin>>width; cout<<"The area of the object is "; int area; area= length*width; cout<<area; cin.get(); return EXIT_SUCCESS; }
Oh, one of the most annoying things in the world, that sh*t..
I have also very much struggled/been annoyed by this. It seems to work for some people and not for others, I'm not sure why. What I have figured is that there are characters "waiting" in the input buffer, which are read by cin, and then -> goodbye. I might be wrong, but this seems to be the problem. I solved this by creating a "FlushInput" function which... flushes the input buffer!Code:cin.get();
I could post the code and some examples to how I use it, if you want, assuming you are using Windows.
A much simpler way of achieving basically the same result (wait for user input) is the
Try it.Code:system("PAUSE");
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
The system pause worked. Thanks. Man thats going to get annoying fast![]()
Bloodshed isn't a compiler.
Right MeTh0dz. Bloodshed makes the IDE, and it comes with MinGW (GCC) as a compiler. I'm not sure if this annoying little problem is related to the compiler.... Is anone using e.g. borland? Same problem there? On borland I think you can also use "getch()" - which is supposed to work... IDK..
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Borland is ****.
Just include conio.h, and you can use getch().
I've never tried borland, so I can't really comment on that one. But if anybody uses it, it would be interesting to know if they had the same problem.
I don't think I have conio.h on my computer.. But I doubt I'm going to need it anyway..
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Methodz way works great. Let me rephrase my other question, where can I get a non beta version of bloodshed C++. I have visual C++ but don't want to use it.
I used to open the command prompt and then run the compiled program by typing its location so the window wouldn't close, lol![]()
Bloodshed DevCpp is no longer in development.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks