¿Se puede usar getch en Dev-C++? por lo menos a mi no me funciona(me baje conio.h)
O tambien me serviria alguna funcion que al pulsar una tecla se introduzca sin nesecidad de enter.
| |||
| problema con getch ¿Se puede usar getch en Dev-C++? por lo menos a mi no me funciona(me baje conio.h) O tambien me serviria alguna funcion que al pulsar una tecla se introduzca sin nesecidad de enter. |
| ||||
| Respuesta: problema con getch Sí, se puede usar.
Código:
Sino trata con system("pause"), #include<stdio.h>
#include<conio.h>
int main(){
getch();
}
Código:
#include <iostream>
int main(){
system ("pause");
}
__________________ Spread Firefox | Download Day 2008 ¡Únete en nuestra misión para alcanzar el Record Guinness al software más descargado en 24 horas! http://www.spreadfirefox.com/es-ES/worldrecord/ Última edición por hgp147; 07/06/2008 a las 17:22 |
| |||
| Respuesta: problema con getch No me funciona, mira el codigo: Cita: Y aqui esta mi conio:#include <iostream> #include <stdlib.h> #include <conio.h> using namespace std; void sumar(); void restar(); void multiplicar(); void dividir(); char x; long a, b, total; float c, d, totald; void sumar() { cout << "Introduce un numero para sumar.\n"; cin >> a; cout << "Ahora introduce el otro numero para sumar.\n"; cin >> b; cout << "La suma de "<< a <<" y "<< b <<" es "<< a + b <<"\n"; } void restar() { cout << "Introduce un numero para ser restado.\n"; cin >> a; cout << "Ahora introduce el numero que restara a "<< a <<".\n"; cin >> b; cout << ""<< a <<" disminuido en "<< b <<" es "<< a - b <<".\n"; } void multiplicar() { cout << "Introduce un numero para multiplicarlo.\n"; cin >> a; cout << "Ahora introduce el otro numero para multiplicarlo con "<< a <<".\n"; cin >> b; cout << ""<< a <<" por "<< b <<" es "<< a * b <<"\n"; } void dividir() { cout << "Introduce un numero para dividirlo.\n"; cin >> c; cout << "Ahora introduce el numero que dividira a "<< c <<".\n"; cin >> d; totald = (float) c / d; printf ("%.1f dividido en %.1f es %.3f \n" ,c,d, totald); } void bucleMain() { cout << "\n\nIntroduce '+' o 's' si quieres sumar\n"; cout << "Introduce '-' o 'r' si quieres restar\n"; cout << "Introduce '*' o 'm' si quieres multplicar\n"; cout << "Introduce '/' o 'd' si quieres dividir\n"; cout << "Si oprimes otra tecla me cerrare\n"; getch(x); switch (x) { case 'S': case 's': case '+': sumar(); break; case 'R' : case 'r': case '-': restar(); break; case 'M' : case 'm': case '*': multiplicar(); break; case 'D' : case 'd': case '/': dividir(); break; case '\n' : case ' ': break; default : exit(0); break; } } main() { cout << "Esta es la Calculadora 1.0 \n"; do { bucleMain(); } while(1); system("PAUSE"); return 0; } Cita: /* * conio.h * This file has no copyright assigned and is placed in the Public Domain. * This file is a part of the mingw-runtime package. * No warranty is given; refer to the file DISCLAIMER within the package. * * Low level console I/O functions. Pretty please try to use the ANSI * standard ones if you are writing new code. * */ #ifndef _CONIO_H_ #define _CONIO_H_ /* All the headers include this file. */ #include <_mingw.h> #ifndef RC_INVOKED #ifdef __cplusplus extern "C" { #endif _CRTIMP char* __cdecl _cgets (char*); _CRTIMP int __cdecl _cprintf (const char*, ...); _CRTIMP int __cdecl _cputs (const char*); _CRTIMP int __cdecl _cscanf (char*, ...); _CRTIMP int __cdecl _getch (void); _CRTIMP int __cdecl _getche (void); _CRTIMP int __cdecl _kbhit (void); _CRTIMP int __cdecl _putch (int); _CRTIMP int __cdecl _ungetch (int); #ifndef _NO_OLDNAMES _CRTIMP int __cdecl getch (void); _CRTIMP int __cdecl getche (void); _CRTIMP int __cdecl kbhit (void); _CRTIMP int __cdecl putch (int); _CRTIMP int __cdecl ungetch (int); #endif /* Not _NO_OLDNAMES */ #ifdef __cplusplus } #endif #endif /* Not RC_INVOKED */ #endif /* Not _CONIO_H_ */ |
| ||||
| Respuesta: problema con getch A mi me anda:
Código:
#include <iostream>
#include <stdlib.h>
using namespace std;
void sumar();
void restar();
void multiplicar();
void dividir();
char x;
long a, b, total;
void sumar() {
cout << "Introduce un numero para sumar.\n";
cin >> a;
cout << "Ahora introduce el otro numero para sumar.\n";
cin >> b;
cout << "La suma de "<< a <<" y "<< b <<" es "<< a + b <<"\n";
}
void restar() {
cout << "Introduce un numero para ser restado.\n";
cin >> a;
cout << "Ahora introduce el numero que restara a "<< a <<".\n";
cin >> b;
cout << ""<< a <<" disminuido en "<< b <<" es "<< a - b <<".\n";
}
void multiplicar() {
cout << "Introduce un numero para multiplicarlo.\n";
cin >> a;
cout << "Ahora introduce el otro numero para multiplicarlo con "<< a <<".\n";
cin >> b;
cout << ""<< a <<" por "<< b <<" es "<< a * b <<"\n";
}
void dividir() {
cout << "Introduce un numero para dividirlo.\n";
cin >> a;
cout << "Ahora introduce el numero que dividira a "<< a <<".\n";
cin >> b;
cout << ""<< a <<" dividido en "<< b <<" es "<< a / b <<"\n";
cout << "Y sobra "<< a % b <<".\n";
}
void bucleMain() {
cout << "Esta es la Calculadora 1.0 beta\n";
cout << "Introduce '+' o 's' si quieres sumar\n";
cout << "Introduce '-' o 'r' si quieres restar\n";
cout << "Introduce '*' o 'm' si quieres multplicar\n";
cout << "Introduce '/' o 'd' si quieres dividir\n";
cout << "Si oprimes otra tecla me cerrare\n";
cin >> x;
switch (x) {
case 'S': case 's': case '+':
sumar();
break;
case 'R' : case 'r': case '-':
restar();
break;
case 'M' : case 'm': case '*':
multiplicar();
break;
case 'D' : case 'd': case '/':
dividir();
break;
case '\n' : case ' ':
break;
default : exit(0);
break;
}
}
main()
{
do { bucleMain(); }
while(1);
system("PAUSE");
return 0;
}
conio.h
Código:
/*
* conio.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Low level console I/O functions. Pretty please try to use the ANSI
* standard ones if you are writing new code.
*
*/
#ifndef _CONIO_H_
#define _CONIO_H_
/* All the headers include this file. */
#include <_mingw.h>
#ifndef RC_INVOKED
#ifdef __cplusplus
extern "C" {
#endif
_CRTIMP char* __cdecl _cgets (char*);
_CRTIMP int __cdecl _cprintf (const char*, ...);
_CRTIMP int __cdecl _cputs (const char*);
_CRTIMP int __cdecl _cscanf (char*, ...);
_CRTIMP int __cdecl _getch (void);
_CRTIMP int __cdecl _getche (void);
_CRTIMP int __cdecl _kbhit (void);
_CRTIMP int __cdecl _putch (int);
_CRTIMP int __cdecl _ungetch (int);
#ifndef _NO_OLDNAMES
_CRTIMP int __cdecl getch (void);
_CRTIMP int __cdecl getche (void);
_CRTIMP int __cdecl kbhit (void);
_CRTIMP int __cdecl putch (int);
_CRTIMP int __cdecl ungetch (int);
#endif /* Not _NO_OLDNAMES */
#ifdef __cplusplus
}
#endif
#endif /* Not RC_INVOKED */
#endif /* Not _CONIO_H_ */
__________________ Spread Firefox | Download Day 2008 ¡Únete en nuestra misión para alcanzar el Record Guinness al software más descargado en 24 horas! http://www.spreadfirefox.com/es-ES/worldrecord/ |