Buscar

bucle for, no me corre


 
 Old 01 feb 2009, 23:14   #1 (permalink)  
Nuevo miembro
 
Avatar de venezolan@
 
Registrado: enero 2009
Mensajes: 24

Sorpresa bucle for, no me corre

#include<stdio.h>
#include<conio.h>

main()
{
int i,VP[6],sumaP;

i=0;
while (i<6)
{
printf("\n Ingrese Porcentaje: ");
scanf("%d",&VP[i]);
if((VP[i]<5)||(VP[i]>30))
printf ("ERROR, el Porcentaje debe estar entre 5% y 30%");
else
i++;
}

for (i=0;i==5;i++)
{
sumaP=sumaP+VP[i];
}

VP[6]=100-sumaP;

printf("\n El último porcentaje es: %d",&VP[6]);

clrscr();
getch();
return 0;
}//fin main


me gustaria q alguien me ayudara.. el bucle for no me quiere correr no hace nada despues de validar
venezolan@ is offline   Citar y responder
 
 Old 01 feb 2009, 23:40   #2 (permalink)  
Ex-miembro
 
Avatar de Hirako
 
Registrado: octubre 2008
Mensajes: 431

Predeterminado Re: bucle for, no me corre

Holas,
Cita:
venezolan@ escribió: Ver post
for (i=0;i==5;i++)
{
sumaP=sumaP+VP[i];
}
Allí esta el problema, debería ser:

Código:
for (i=0;i<=5;i++)
 {
   sumaP=sumaP+VP[i];
 }
Lo que hacías era que nunca llegara a condición, puesto que el "for" entraría siempre y cuando "i" valiera 5, partiendo que lo inicializaste en 0 nunca llegará a 5 dentro de ese fragmento de código.

Saludos
Hirako is offline   Citar y responder
 
 Old 01 feb 2009, 23:54   #3 (permalink)  
Nuevo miembro
 
Avatar de venezolan@
 
Registrado: enero 2009
Mensajes: 24

Predeterminado Re: bucle for, no me corre

Gracias amigo...
venezolan@ is offline   Citar y responder

« Crear mi propia pagina web | para hacer programas »

Herramientas
Estilo


 

Tema Iniciado por Foro Respuestas Último mensaje
Bucle mientras rojiblanc0 Programación 10 11 abr 2010 20:41
bucle en test drive Kifli Juegos 2 21 mar 2008 00:40
no corre el virtualbox Franklindsfranco Software para Linux 7 16 feb 2008 00:05
Corre, Corre......... chicho terremoto Un poco de todo 0 01 ene 2008 14:36
porque Ares corre lento? gunnnnnnsssssnn P2P 5 05 dic 2007 09:54



Buscar