elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / RESOLUCION C++ en: 24 Febrero 2015, 03:05 am
Alguien sabe como ajustar la pantalla del compilador de c++ agregando ancho y altura por ejemplo 1024 * 780 ??????? que comando debo usar segun la programacion de c++
2  Programación / Programación C/C++ / Como hacer que un bucle no se infinito cuando ingreso letras en un switch en: 29 Noviembre 2014, 22:52 pm
Buenas a todos tengo un problema con mi switch, tengo mi menu normal completo en mi int main (); pero cuando lo ejecuto arranca normal, le tengo ingresado numeros para que ingrese a nuevos menus pero si yo coloco letras le he puesto un mensaje de error y luego que continue en el programa, pero el se buclea solo infinitamente sin para, y me han dicho que haga comparacion de cadenas con numeros para que no me siga bucleando el programa pero no se como hacer para que se buclee y me deje seguir introduciendo numeros o letras en el switch. Aqui les dejo el codigo.

Tambien lo pueden descargar de aqui y abrirlo directamente tanto el codigo como el programa: https://mega.co.nz/#F!4M9hUKBJ!jA_TDwhQ0pCxJN3tzg6Zrg

Código
  1. #include <iostream>
  2. #include <string.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8. /*Diseñado por Addison Jimenez*/
  9.  
  10. void sumar();
  11. void restar();
  12. void multiplicar();
  13. void dividir();
  14.  
  15. FILE *pf;
  16.  
  17. int op;
  18. float num_1;
  19. float resultado_sumar;
  20. float resultado_restar;
  21. float resultado_multiplicar;
  22. float resultado_dividir;
  23.  
  24. int main() {
  25. system("color 0a");
  26. ofstream verificando;
  27. verificando.open("info.txt");
  28. {
  29. ofstream verificando("info.txt");
  30. verificando << "================================================================ \n";
  31. verificando << "      BIENVENIDO USUARIO A LA CALCULADORA (4 FUNCIONES) \n";
  32. verificando << "================================================================ \n";
  33. verificando.close();
  34. }
  35. do{
  36. {
  37. ifstream verificando("info.txt");
  38. if(verificando.fail())
  39. cout << "ERROR AL ABRIR EL ARCHIVO SOLICITADO \n";
  40. verificando.close();
  41. }
  42. cout << "============================================================================== \n";
  43. cout << "              BIENVENIDO USUARIO A LA CALCULADORA (4 FUNCIONES) \n";
  44. cout << "============================================================================== \n\n";
  45. cout << "\tELIGE LA OPERACION A REALIZAR DE LOS DOS NUMEROS ANTERIORES \n\n";
  46. cout << "\n\t\t\t1.* SUMA";
  47. cout << "\n\t\t\t2.* RESTA";
  48. cout << "\n\t\t\t3.* MULTIPLICACION";
  49. cout << "\n\t\t\t4.* DIVISION";
  50. cout << "\n\t\t\t5.* SALIR DEL APLICATIVO";
  51. cout << "\n\n\t\t\tELIGE TU OPCION: ";
  52. cin >> op;
  53. system("cls");
  54. switch(op){
  55. case 1: sumar();
  56. break;
  57. case 2: restar();
  58. break;
  59. case 3: multiplicar();
  60. break;
  61. case 4: dividir();
  62. break;
  63. case 5:
  64. system("color 0d");
  65. cout << "============================================================================== \n";
  66. cout << "\n\n\t\t   FINALIZO EL PRORGAMA! VUELVA PRONTO\n\n\n";
  67. cout << "============================================================================== \n\n";
  68. break;
  69. default:
  70. system("color 0c");
  71. cout << "============================================================= \n";
  72. cout << "\tERROR - INTRODUZCA OTRA OPCION O NUMERO\n";
  73. cout << "============================================================= \n\n";
  74. cin >> op;
  75. getch();
  76. system("cls");
  77. fflush(stdin);
  78. break;
  79. }
  80. }while(op!=5);
  81. getch();
  82. return EXIT_SUCCESS;
  83. }
  84. void sumar(){
  85. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  86. {
  87. ifstream verificando("info.txt");
  88. if(verificando.fail())
  89. cout << "ERROR AL ABRIR EL ARCHIVO SOLICITADO \n";
  90. verificando.close();
  91. }
  92. system("color 0b");
  93. cout << "============================================================================== \n";
  94. cout << "              BIENVENIDO USUARIO A LA CALCULADORA (4 FUNCIONES) \n";
  95. cout << "============================================================================== \n\n";
  96.  
  97. cout << "DIGITE EL PRIMER NUMERO\n";
  98. cin >> resultado_sumar;
  99. cout << "\n";
  100.  
  101. string seguir;
  102.  
  103. do {
  104. cout << "DIGITE EL SEGUNDO NUMERO\n";
  105. cin >> num_1;
  106. cout << "\n";
  107.  
  108. resultado_sumar = num_1 + resultado_sumar;
  109.  
  110. system("color 0b");
  111. cout << "EL RESULTADO ES: " << resultado_sumar << "\n\n";
  112.  
  113. cout << "DESEA CONTINUAR SUMANDO DIGITE (si/no)\n";
  114. cin >> seguir;
  115. cout << "\n\n";
  116. } while (seguir!="no");
  117. {
  118. ofstream extrayendo;
  119. extrayendo.open("resultados_sumar.txt", ios::out|ios::app);
  120. extrayendo << "================================================================ \n";
  121. extrayendo << "PRIMER NUMERO " << resultado_sumar << " == SEGUNDO NUMERO " << num_1 << " == RESULTADO" << resultado_sumar << "\n";
  122. extrayendo << "================================================================ \n";
  123. extrayendo.close();
  124. }
  125.  
  126. system("color 0e");
  127. cout << "LOS DATOS INGRESADOS FUERON EXPORTADOS EN ARCHIVO TEXTO\n";
  128. system("pause");
  129. system("cls");
  130. system("color 0a");
  131. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  132. }
  133. void restar(){
  134. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  135.  
  136. {
  137. ifstream verificando("info.txt");
  138. if(verificando.fail())
  139. cout << "ERROR AL ABRIR EL ARCHIVO SOLICITADO \n";
  140. verificando.close();
  141. }
  142.  
  143. system("color 0b");
  144.  
  145. cout << "============================================================================== \n";
  146. cout << "              BIENVENIDO USUARIO A LA CALCULADORA (4 FUNCIONES) \n";
  147. cout << "============================================================================== \n\n";
  148.  
  149. cout << "DIGITE EL PRIMER NUMERO\n";
  150. cin >> resultado_restar;
  151. cout << "\n";
  152.  
  153. string seguir;
  154.  
  155. do {
  156. cout << "DIGITE EL SEGUNDO NUMERO\n";
  157. cin >> num_1;
  158. cout << "\n";
  159.  
  160. resultado_restar = num_1 - resultado_restar;
  161.  
  162. cout << "EL RESULTADO ES: " << resultado_restar << "\n\n";
  163.  
  164. cout << "DESEA CONTINUAR RESTANDO DIGITE (si/no)\n";
  165. cin >> seguir;
  166. cout << "\n\n";
  167. } while (seguir!="no");
  168. {
  169. ofstream extrayendo;
  170. extrayendo.open("resultados_restar.txt", ios::out|ios::app);
  171. extrayendo << "================================================================ \n";
  172. extrayendo << "PRIMER NUMERO " << resultado_restar << " == SEGUNDO NUMERO " << num_1 << " == RESULTADO" << resultado_restar << "\n";
  173. extrayendo << "================================================================ \n";
  174. extrayendo.close();
  175. }
  176.  
  177. system("color 0e");
  178. cout << "LOS DATOS INGRESADOS FUERON EXPORTADOS EN ARCHIVO TEXTO\n";
  179. system("pause");
  180. system("cls");
  181. system("color 0a");
  182. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  183. }
  184. void multiplicar(){
  185. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  186.  
  187. {
  188. ifstream verificando("info.txt");
  189. if(verificando.fail())
  190. cout << "ERROR AL ABRIR EL ARCHIVO SOLICITADO \n";
  191. verificando.close();
  192. }
  193. system("color 0b");
  194.  
  195. cout << "============================================================================== \n";
  196. cout << "              BIENVENIDO USUARIO A LA CALCULADORA (4 FUNCIONES) \n";
  197. cout << "============================================================================== \n\n";
  198.  
  199. cout << "DIGITE EL PRIMER NUMERO\n";
  200. cin >> resultado_multiplicar;
  201. cout << "\n";
  202.  
  203. string seguir;
  204.  
  205. do {
  206. cout << "DIGITE EL SEGUNDO NUMERO\n";
  207. cin >> num_1;
  208. cout << "\n";
  209.  
  210. resultado_multiplicar = num_1 * resultado_multiplicar;
  211.  
  212. cout << "EL RESULTADO ES: " << resultado_multiplicar << "\n\n";
  213.  
  214. cout << "DESEA CONTINUAR MULTIPLICANDO DIGITE (si/no)\n";
  215. cin >> seguir;
  216. cout << "\n\n";
  217. } while (seguir!="no");
  218. {
  219. ofstream extrayendo;
  220. extrayendo.open("resultados_multiplicar.txt", ios::out|ios::app);
  221. extrayendo << "================================================================ \n";
  222. extrayendo << "PRIMER NUMERO " << resultado_multiplicar << " == SEGUNDO NUMERO " << num_1 << " == RESULTADO" << resultado_multiplicar << "\n";
  223. extrayendo << "================================================================ \n";
  224. extrayendo.close();
  225. }
  226. system("color 0e");
  227. cout << "LOS DATOS INGRESADOS FUERON EXPORTADOS EN ARCHIVO TEXTO\n";
  228. system("pause");
  229. system("cls");
  230. system("color 0a");
  231. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  232. }
  233. void dividir(){
  234. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  235.  
  236. ifstream verificando("info.txt");
  237. if(verificando.fail())
  238. cout << "ERROR AL ABRIR EL ARCHIVO SOLICITADO \n";
  239. verificando.close();
  240. system("color 0b");
  241.  
  242. cout << "============================================================================== \n";
  243. cout << "              BIENVENIDO USUARIO A LA CALCULADORA (4 FUNCIONES) \n";
  244. cout << "============================================================================== \n\n";
  245.  
  246. cout << "DIGITE EL PRIMER NUMERO\n";
  247. cin >> resultado_dividir;
  248. cout << "\n";
  249.  
  250. cout << "DIGITE EL SEGUNDO NUMERO\n";
  251. cin >> num_1;
  252. cout << "\n";
  253.  
  254. resultado_dividir = num_1 / resultado_dividir;
  255.  
  256. cout << "EL RESULTADO ES: " << resultado_dividir << "\n\n";
  257.  
  258. if (resultado_dividir==0) {
  259. system("color 0c");
  260. cout << "NUNCA SE PUEDE DIVIDIR POR CERO \n\n";
  261. } else {
  262. resultado_dividir = resultado_dividir/num_1;
  263. }
  264. {
  265. ofstream extrayendo;
  266. extrayendo.open("resultados_dividir.txt", ios::out|ios::app);
  267. extrayendo << "================================================================ \n";
  268. extrayendo << "PRIMER NUMERO " << resultado_dividir << " == SEGUNDO NUMERO " << num_1 << " == RESULTADO" << resultado_dividir << "\n";
  269. extrayendo << "================================================================ \n";
  270. extrayendo.close();
  271. }
  272. system("color 0e");
  273. cout << "LOS DATOS INGRESADOS FUERON EXPORTADOS EN ARCHIVO TEXTO\n";
  274. system("pause");
  275. system("cls");
  276. system("color 0a");
  277. fflush(stdin); // Para limpiar el bufer y no haya problemas con la entrada de caracteres.
  278. }
  279.  
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines