Dev C++ not working fine

Aug 18, 2010 at 1:35pm
So I downloaded Dev C++ which is very hard to use since at our Programming class, we use MS Visual Studio 6.0 and it's not a freeware so i can't download online.
My problem with Dev C++ is that my codes run but it closes when I enter something.
Also, are there anymore IDE/compiler as alternative for MS VS 6.0?
Aug 18, 2010 at 1:46pm
Write this before return statement
 
system("PAUSE");


Other FREE c++ IDE are:
codeblocks: www.codeblocks.org

msvc++ Express: www.msdn.com

Expert will tell you more.
Aug 18, 2010 at 1:55pm
I already tried adding that code. I don't know where to put it. And it doesn't work.
Aug 18, 2010 at 1:56pm
Give me your code here..i have DEV C++ too.
Aug 18, 2010 at 1:59pm
look at this....
1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
#include<string>
using namespace std;

int main(){
string fname;
cout<<"Your  first name please: "<<endl;
cin>>fname;
system("PAUSE");
return 0;
}
Aug 18, 2010 at 2:00pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//Exercise 14
#include <iostream.h>
#include <string> 
#include <limits>
int main ()

{
	char cc;

	cout <<"Enter course code:";
	cin >> cc;

	if ((cc=='a') || (cc=='A'))
		cout <<"Accounting" << endl;

	else if ((cc=='b') || (cc=='B'))
		cout <<"Banking and Finance" << endl;

	else if ((cc=='c') || (cc=='C'))
		cout <<"BSIT" << endl;

	else 
		cout <<"Invalid course" << endl; 

	return 0;

}
Last edited on Aug 18, 2010 at 2:00pm
Aug 18, 2010 at 2:06pm
HERE the solution..but i thinks there is no need to include these
1
2
#include <string> 
#include <limits> 


your program will be..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	//Exercise 14
#include <iostream.h>

int main ()

{
	char cc;

	cout <<"Enter course code:";
	cin >> cc;

	if ((cc=='a') || (cc=='A'))
		cout <<"Accounting" << endl;

	else if ((cc=='b') || (cc=='B'))
		cout <<"Banking and Finance" << endl;

	else if ((cc=='c') || (cc=='C'))
		cout <<"BSIT" << endl;

	else 
		cout <<"Invalid course" << endl; 
		
system("PAUSE");
	return 0;

}
Aug 18, 2010 at 2:08pm
I think we can be friend-after you PM me.
Aug 18, 2010 at 2:20pm
Thanks. It works now.

Also, since I'm too lazy to make a new thread, WHEN will you include the <string>?
Our stupid instructor didn't teach us.
Aug 18, 2010 at 2:36pm
<string>


Is used when you need to create string datatype, like in my sample above i needed to take user name which is string---I included <string> library because string is not fundamental datatype as float ,double...e.t.c

try to delete it...
Aug 18, 2010 at 2:39pm
Aug 19, 2010 at 2:48am
I had the problem again! Some of my codes doesn't work using system("PAUSE");
Our instructor never taught us to use that code! Do I really need to put that code on EVERY program I make on DevC++!?
Aug 19, 2010 at 7:53am
The closing down isn't due to devc++...

it's just an ide, so it works correct, only if you do correct coding (just like all ide's and programs)..

What you need to do is add cin.ignore(numeric_limits<streamsize>::max(), '\n');

What this does is wait for enter to be pressed.. This is better then system("pause")...

And yes, you need to place something like this in every program, unless you want it to run successfully and then close down. What this (and system(pause)) does is wait for the user to press enter when ready. So now the program has to wait with closing down until the user presses enter :)

Cheers!
Aug 19, 2010 at 8:02am
I'm using MVC++ 2010 Express for my IDE and it doesn't exit programs as soon as they're done so it can be to do with the IDE you're using. One thing you can do is create a batch file in Notepad witch contains two lines, the program name (e.g. Hello_world.exe) and 'pause' then save it with the .bat extension. That should stop it from exiting immediately at the finish if you double click that batch file or you could use a different IDE that automatically keeps open the command window.
Aug 20, 2010 at 1:36pm
okay!i was out..i think you can ask user to enter some value to exit.example.
1
2
3
4
int x;
do{cout<<"enter 3 to exit";
//your code goes here.
}while(x==3)
Topic archived. No new replies allowed.