Alguem Me Ajuda A Resolver Esse Errinho?
Olá, Eu Preciso criar um codigo para cadastrar 20 clientes em um posto de gasolina, e depois fazer a somatoria de quanto gastou
Minha duvida é a seguinte, eu coloquei pra cadastrar só 20, mas, antes de fazer a somatoria, aparece um 21° pra eu digitar o combustivel utilizado e quantos litros, eu gostaria de saber o que eu tenho que mudar, pra esse 21° não aparecer, e após cadastrar o ultimo 20°, ele somar tudo de uma vez já...
Grata desde já
#include <cstdio>
#include <string.h>
#include <iostream>
#include <conio.h>
int main(){
int i, VETOR_A[100], Cont=0;
char VETOR_B[100], Op= 'S', Aux[10];
float VETOR_C[100], PRECO , SOMA=0;
do{
printf("\nCLIENTE %d:\n\n", Cont+1);
printf("DIGITE O COMBUSTIVEL UTILIZADO:\n \n= G = GASOLINA - R$ 4,49\n= E = ETANOL - R$ 2,69\n= D = DIESEL - R$ 3,39\n\n");
do{
fflush(stdin);
scanf ("%c", &VETOR_B[Cont]);
if (toupper(VETOR_B[Cont])=='G'){strcpy(Aux,"GASOLINA"); PRECO=4.49; Op= 'p';}
else if(toupper(VETOR_B[Cont])=='E'){strcpy(Aux,"ETANOL" ); PRECO=2.69; Op= 'p';}
else if(toupper(VETOR_B[Cont])=='D'){strcpy(Aux,"DIESEL" ); PRECO=3.39; Op= 'p';}
else {printf("COMBUSTIVEL NAO CADASTRADO, SO E PERMITIDO OS TRES COMBUSTIVEIS CADASTRADO NO SISTEMA\n"); }
}while (Op != 'p');
do{
printf ("\nDIGITE O TOTAL DE LITROS%S ABASTECIDO: ", Aux);
fflush (stdin);
scanf ("%d", &VETOR_A[Cont]);
if (VETOR_A[Cont] >=0){
VETOR_C[Cont] = (float)VETOR_A[Cont] * PRECO;
}
else{
printf("NAO PODE EXISTIR VALOR NEGATIVO...!\n");
}
}while(VETOR_A[Cont] < 0);
if(Cont < 20)Cont++;
else {
getch();
Op='N';
}
}while(toupper(Op) != 'N');
printf("\n");
for(i=0; i<Cont; i++){
printf("TOTAL DE LITROS ABASTECIDO: %d COMBUSTIVEL UTILIZADO: %c VALOR TOTAL: %2f\n",VETOR_A[i], VETOR_B[i], VETOR_C[i]);
SOMA += VETOR_C[i];
}
printf("\nVALOR TOTAL ARRECADADO NO DIA -> R$ %.2f\n\n",SOMA);
getch();
return 0;
}Discussão (0)
Carregando comentários...