while not running from the beginning

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

main(){

 int parar=1; // Condição para parar.
 int a=0, b=0, c=0; //Elevadores
 int count=0; //Numero de pessoas
 char elevador=""; //Elevador

do{

  printf("Elevador: ");
  scanf("%c", &elevador);

  if(elevador == 'a'){
    a++;
    count++;
  }else if(elevador == 'b'){
    b++;
    count++;
  }else if(elevador == 'c'){
     c++;
     count++;
  }else{
     printf("inválido!");
  }

    printf("\nContinuar respondendo? s=1 n=0");
    scanf("%d", &parar);

  }while(parar != 0);
}

I am creating a mini form for search but it is not running correctly, see how it is returned to me:

    
asked by anonymous 13.06.2017 / 05:21

2 answers

3

The basic problem with the code is that it is initializing a character as if it were a string , there is code that does not read correctly with the information. Use single quotation marks for char .

This code can be improved, but it's not even worth doing because it is not even complete.

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

int main() {
    int parar = 1; // Condição para parar.
    int a = 0, b = 0, c = 0; //Elevadores
    int count = 0; //Numero de pessoas
    char elevador=' '; //Elevador
    do {
        printf("Elevador: ");
        scanf("%c", &elevador);
        if (elevador == 'a') {
            a++;
            count++;
        } else if (elevador == 'b') {
            b++;
            count++;
        } else if (elevador == 'c') {
           c++;
           count++;
        } else {
            printf("inválido!");
        }
        printf("\nContinuar respondendo? s=1 n=0");
        scanf("%d", &parar);
    } while (parar != 0);
}

See running on ideone . And no Coding Ground . Also I put it in GitHub for future reference .

    
13.06.2017 / 05:49
-1

Good evening. In the code you posted you have a key that is not opening

// this one down where I left bold

} while (stop! = 0); }

    
13.06.2017 / 05:32