<div dir="ltr">Hola Martín,<div class="gmail_extra"><br><div class="gmail_quote">2013/6/13 Martín Melo Godínez <span dir="ltr"><<a href="mailto:nitram-210397@hotmail.com" target="_blank">nitram-210397@hotmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">

<div>Hola que tal quisiera ver si me podría ayudar en un problema de Vectores o Arreglos Undimensionales. Tengo un problema el cual me dice que almacene vector el numero de peso de n empleados. Como podrán ver el tamaño del vector será el numero que introduzca en el teclado, pero no se como declarar esa instrucción, Si alguien me podría corregir lo agradecería mucho:</div>

<div> </div></div></div></blockquote><div><br></div><div>Veamos el código fuente.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">

<div>#include<iostream.h><br>#include<conio.h><br>#include<stdio.h><br></div></div></div></blockquote><div><br></div><div>Deberías usar los nombres estándares de C++ para los ficheros estándares de cabecera, que en este caso son:<br>

<br>#include <iostream></div><div>#include <cstdio><br></div><div><br></div><div>Tendrás que usar el espacio de nombre 'std'. Lo más sencillo es escribir:<br><br>using namespace std;</div>
<div><br></div><div>Por cierto, <conio.h> no es estándar.</div><div><br></div><div>Ahora bien, es posible que estés usando un compilador antiguo y lo que te acabo de decir no funcione en tu compilador.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">

<div>#define tam ne<br></div></div></div></blockquote><div><br></div><div>Esto no tiene mucho sentido. Puedes eliminar esta directiva.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">

<div>void main()<br></div></div></div></blockquote><div><br></div><div>El estándar de C++ dicta que 'main()' debe retornar un entero. Por convenio, retornamos 0 (cero) para indicar una terminación correcta del programa.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">

<div>{<br> int ne,x;<br>   int peso[ne];<br></div></div></div></blockquote><div><br></div><div>Esto no es correcto. El valor para la cantidad máxima de elementos debe ser constante.</div><div><br></div><div>
Tienes dos opciones: o bien (1) indicas una cantidad máxima - y constante - para el array pero usando una variable para representar la cantidad actual de elementos, o bien (2) manejas memoria dinámicamente adjudicada para crear un array dinámico.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
<div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">

<div>   cout<<"Cuantos empleados son: "<<endl;<br>   cin>>ne;<br>   for(x=1;x<=tam;x++)<br></div></div></div></blockquote><div><br></div><div style>Como usas 'x' como índice para el array, debes empezar por 0 (cero), y por tanto el índice del último elemento será 1 menos de la cantidad actual de elementos.</div>
<div style><br></div><div style>En este ejemplo, reescribimos la cabecera del bucle 'for' así,</div><div style><br></div><div style>for( x=0; x<ne; x++ )</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">
<div>   {<br>    cout<<"Da el peso del empleado "<<x<<endl;<br>      cin>>peso[x];<br>
   }<br>   for(x=1;x<=tam;x++)<br></div></div></div></blockquote><div><br></div><div style>Aquí, lo mismo; los índices siempre empiezan por cero.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">
<div>   {<br>    if(peso[x]<=80)<br>      {<br>       cout<<"El peso es menor o igual de 80 kg"<<endl;<br>      }<br>      else if(peso[x]>80)<br></div></div></div></blockquote><div><br></div><div style>
No es un error, pero no tiene mucho sentido comprobar algo que sabemos que es verdad. Si llegamos a la parte de 'else', entonces sabemos que la condición de la primera sentencia, 'if', es falsa. Si algo no es ni menor ni igual a 80, por lógica debe ser mayor a 80; no es necesario comprobar este caso.</div>
<div style><br></div><div style>Simplemente, escribe 'else' y elimina esta segunda sentencia 'if'.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt">
<div>      {<br>       cout<<"El peso del empleado "<<x<<" excede de 80 kg"<<endl;<br>
      }<br>   }<br>   getch();<br>}</div><div><div> </div></div></div></div></blockquote><div><br></div><div><br></div><div style>Espero que esto te oriente.</div><div><br></div><div style>Steven</div><div style><br></div>
</div></div></div>