AprendendoC Posted April 22, 2012 at 06:04 PM Report #450555 Posted April 22, 2012 at 06:04 PM 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..
KTachyon Posted April 22, 2012 at 07:01 PM Report #450568 Posted April 22, 2012 at 07:01 PM 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
AprendendoC Posted April 22, 2012 at 08:54 PM Author Report #450591 Posted April 22, 2012 at 08:54 PM #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...
KTachyon Posted April 22, 2012 at 09:08 PM Report #450595 Posted April 22, 2012 at 09:08 PM 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
AprendendoC Posted April 22, 2012 at 09:11 PM Author Report #450597 Posted April 22, 2012 at 09:11 PM obrigadao... amigo... consegui resolver o problema... gracias..
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now