Teen Programmers Unite  
 

 

Return to forum top

Dev-C++ help

Posted by mattlynam2002 [send private reply] at September 04, 2002, 12:29:25 PM

Hi All !
I have a problem in DevC++,when i make any Win32 Console App.For example my one below !

#include <iostream>
int main ()
{
int no1, no2, no3;
cout << "Please enter a number:";
cin >> no1 ;
cout << "Another:";
cin >> no2;
cout << "\nChoose a number corrosponding to
the mathmatical operation desired:\n
1 = Add
2 = Multiply
3 = Subtract
4 = Devide\n";
cin >> no3;
switch (no3)
{
case 1:
cout << no1 << "+" << no2 << "=" << no1 + no2;
break;
case 2:
cout << no1 << "*" << no2 << "=" << no1 * no2;
break;
case 3:
cout << no1 << " - " << no2 << "=" << no1 - no2;
break ;
case 4:
cout << no1 << "/" << no2 << "=" << no1 / no2;
default:
cout << "Incorrect input,quitting !";
break ;
}
return 0;
}
Is hasnt no errors as far as i know !
Anyway the problem is when run my programs you never get to see he end of it properly,because it closes down auto.Unlike in Visual C++ it auto sez "press any key to exit" or somit along the lines.
Is this a feature in DevC++ i can turn off or have any of you got some code i can add to make it pause !
Please help !
Sorry if you have no idea wot im on about !

Posted by regretfuldaydreamer [send private reply] at September 04, 2002, 01:10:43 PM

Just add:

cout << "\n Press any key to quit";
char c;
cin >> c;

before return 0;
Posted by CViper [send private reply] at September 04, 2002, 03:11:56 PM

alternativly type

cout << "Press any key";
getch();


Don't forget to include <conio.h> though!
(in RDD's example you have to push enter i think...)
Posted by mattlynam2002 [send private reply] at September 04, 2002, 03:42:09 PM

Thanx it works apart from cvipers solution it comes up with this compile error below !

implicit declaration of function `int getchar(...)'

And i have added <conio.h>

Posted by CodeRed [send private reply] at September 04, 2002, 03:46:04 PM

CVipers solution is the best way to do it, I use getch() in that way all the time in VC++

Posted by CViper [send private reply] at September 04, 2002, 03:49:40 PM

mattlynam2002: it's supposed to be "getch()" not "getchar()"

Posted by mattlynam2002 [send private reply] at September 04, 2002, 04:01:43 PM

That error above is "the" compile error,i did type in getch() not getchar() and thats what it sez !
Yeah it does work in Visual C++ but i want to use DevC++

Posted by unknown_lamer [send private reply] at September 04, 2002, 04:45:36 PM

What? std::cin.get() works better and doesn't rely on DOS only crap. That, and stdio (which I bet conio uses) isn't always synced with iostreams unless you set an option that would kill performance.

Posted by whizkide [send private reply] at September 04, 2002, 07:47:24 PM

easiest way to do it is..........
system("pause");
that gives you what you get when using MSVC++. it works on dev-c++ since its a system call. But as u know, system calls slow down ur app. but for the simple program up there, spped isnt a concern.
whizzzzzzzzzzzzzzzz

Posted by mattlynam2002 [send private reply] at September 05, 2002, 03:09:37 PM

OK thanx all !

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.