-1

Everytime the code runs, it asks 1 time at first and then asks twice for the character input, i am pretty new to programming

I tried using while, but i had the same result, i cant spot my mistake

#include <stdio.h>
#include <stdlib.h>

int main()
{
system("cls");

int contador;
int caracterA=0;
int otrosCaracteres=0;
char ingresoCaracteres;

for(contador=0;contador<=5;contador++)
{
 printf("\n Ingrese caracteres");
    scanf("%c",&ingresoCaracteres);
     contador++;
}

if(ingresoCaracteres=='a')
{
    caracterA++;
}
if(ingresoCaracteres=='e','i','o','u')
{
    otrosCaracteres++;
}

printf("Entered a: %d",caracterA);
printf("Entered e,i,o,u: %d",otrosCaracteres);

return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Luciano
  • 3
  • 1
  • 1
    Update your answer to include desired behavior. It's a bit difficult to tell what the goal is. – bejado Mar 26 '17 at 00:53
  • 1
    You have many small bugs. A few include: 1) Move the if statements inside the loop. 2) You probably want to get rid of the line "contador++;" This will cause your loop index to move forward 2 steps each time instead of 1. 3) The second if statement can't be written like that in C. Look up conditional statements with "or" (||) – jeff carey Mar 26 '17 at 00:56

1 Answers1

0

Take a secondary variable in the 'for' loop.

You're increasing the value of 'contador'; but as it goes again in the for loop, it sets the value of 'contador' to '0'

Nish
  • 71
  • 1
  • 4