After typing the P Value, you are not running the printf of the second for

Asked

Viewed 32 times

0

#define MAX 15
#define TAM 2
struct
{
    char m[MAX];
    int ano;
    float v;
} car[TAM];

int main(void)
{
    int i;
    int p;

    for(i=0; i<TAM; i++)
    {
        printf("Determine a Marca e Modelo do Carro %d: ", i+1);
        gets(car[i].m);
        printf("Determine o Ano do Carro %d: ", i+1);
        scanf("%d", &car[i].ano);
        printf("Determine o Valor do Carro1 %d: ", i+1);
        scanf("%f", &car[i].v);
        fflush(stdin);
    }

    printf("Determine o seu Orcamento: ");
    scanf("%f", &p);

    for(i<0; i<TAM; i++)
    {
        if(car[i].v<p)
        {
            printf("Marca: %s\nAno: %d\nPreco: %.2f", car[i].m, car[i].ano, car[i].v);
        }
    }
    return 0;
}
  • in the second for the beginning is wrong and should be i = 0 and not i < 0. That’s a typo right there.

2 answers

0

Look at this:

int p;
// ...
scanf("%f", &p);

I think what you wanted was this:

float p;
// ...
scanf("%f", &p);

I mean, it was to use float instead of int.

Also, never use it gets. In the your other question, you already used the fgets, use here too.

-1

Hello, I also found only these mistakes:

The second one should be like this:

for(i = 0; i<TAM; i++) /*igual em vez de menor*/

You used P as a float but declared it int

int p;

The colleagues had already mentioned it, here it is running correctly.

Hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.