While Repeating Structure Problem

Asked

Viewed 28 times

0

I have this exercise to do but I’m not getting it, it asks to use while but how will I save the data since I do not know the amount of variables for each book, since the amount of books varies for each user

The marketing department of a publishing house is having trouble calculating the equilibrium point for any book you propose to publish. The equilibrium point represents the value of the selling price covering production costs. The costs of production consist of a fixed cost plus a copy cost which is equal to the the estimated number of copies multiplied by the number of pages. Thus: production cost = fixed cost + (on an estimated copy x on one page) Read a list containing, for each book, the book identifier (integer value), the fixed cost, the estimated number of copies and the number of pages and print: • the cost of producing each book, • the identifier code and book cost with the highest production cost. Consider that the production cost will always be different. Also, the program shall be terminated when a negative identifier is entered

printf("Digite o numero de livros\n");
scanf("%d", &livros);
cont = 0;
while (cont != livros){
    printf("\nDigite o numero de identificacao do livro\n");
    scanf("%d", &ident);
    printf("Digite o custo fixo do livro\n");
    scanf("%d", &custo);
    printf("Digite o numero estimado de copias do livro\n");
    scanf("%d", &copias);
     printf("Digite o numero estimado de paginas do livro\n");
    scanf("%d", &paginas);
    custoproducao = custo + (copias*paginas);
    cont = cont + 1;
    printf("O custo de producao do livro %d é %.1f", ident, custoproducao);

}
printf("\nO maior custo de producao é %f", custoproducao);
  • Have you thought about using arrays and/or structures and/or dynamic allocation?

  • then, but I can’t because we haven’t had that matter yet, and I haven’t learned yet either you understand..

  • You’re doing the math for every book. To determine the book with the highest production cost check, at each book/calculation, whether the cost is greater than calculated so far and, if so, store the code and the production cost of such book.

  • The problem seems to be more of text interpretation than programming. Everything you need to do is in the statement, the rest is invention.

1 answer

0

You don’t need to save all the data. for example: If it enters a thousand books you can simply ignore all the data and take only what you need.

printf("Digite o numero de livros\n");
scanf("%d", &livros);
cont = 0;
float maior_custo = 0;
while (cont != livros){
    printf("\nDigite o numero de identificacao do livro\n");
    scanf("%d", &ident);
    if(ident < 0){
        break;
    }
    printf("Digite o custo fixo do livro\n");
    scanf("%d", &custo);
    printf("Digite o numero estimado de copias do livro\n");
    scanf("%d", &copias);
    printf("Digite o numero estimado de paginas do livro\n");
    scanf("%d", &paginas);
    custoproducao = custo + (copias*paginas);

    if(custoproducao > maior_custo){
       maior_custo = custoproducao;
    }
    cont = cont + 1;
    printf("O custo de producao do livro %d é %.1f", ident, custoproducao);

}
printf("\nO maior custo de producao é %f", maior_custo);

That?

Browser other questions tagged

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