Jump to content

[Resolvido]Ajuda com Do....While


Recommended Posts

Posted

olá galera... to tentando implementa um laço do while para fazer um cadastro.. Tipo no começo do programa peço ao usuario qntos clientes ele deseja cadastrar... so que nao to conseguindo implementa o do...while pra repetir o numero que o usuario digita..

Posted

Não há muito mais por onde te ajudar:

do { // faz
    // isto
} while (condicao) // enquato a condição é válida

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Posted
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
main(void)
{
          int marca, combustivel, litros, oleo, pagamento, clientes;
          printf("Quantos clientes deseja cadastrar? ");
          scanf("%d", &clientes);
          do{
                 printf("Qual a marca do Veiculo? ");
                 scanf("%d", &marca);
                 printf("Qual foi o Tipo de Combustivel?");
                 scanf("%d", &combustivel);
                 printf("Quantidade de litros: ");
                 scanf("%d", &litros);
                 printf("Trocou O oleo? S - Sim N - Nao");
                 scanf("%d", &oleo);
                 printf("Forma de Pagamento? D - Dinheiro C - Cheque");
                 scanf("%d", &pagamento);
                 
             }while(clientes);
}

tah ai o começo do meu programa.. so que nao to conseguindo fazer com que o laço execute o numero de vezes que o cliente digitar...

Posted

Logo à partida estás a fazer mal. Se à variável clientes é atribuído um valor diferente de zero, a condição do while é sempre verdadeira, logo nunca termina. Uma solução é ires decrementando o valor dessa variável à medida que os clientes são criados pelo utilizador.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.