0
I need to do a program that:
- Get the pc model, its price and display the highest value, plus the amount of computers without peripherals.
- In the main function, receive the amount of peripherals.
- A function that receives as a parameter the number of peripherals, make the sum of their prices.
- display the quantity of sales without additional peripherals and the value of the highest sale.
However, when displaying the highest value, it goes wrong.
Below, the code performed.
#include <stdio.h>
float pg_peri (int qtdper){
float precoperi;
printf ("Digite o valor do periferico:\n");
scanf ("%f",&precoperi);
return precoperi;
}
int main (){
float precomod, maior, pctot, pcperi, somaper;
int cont, qtdperi1, codmod, vdperi, qtdmodelos, cc;
somaper = 0;
vdperi = 0;
cont = 0;
maior = 0;
printf ("Digite quantos computadores deseja comprar\n");
scanf ("%d", &qtdmodelos);
while (cont < qtdmodelos){
printf ("Digite o codigo do modelo desejado e seu preco\n");
scanf ("%d%f", &codmod,&precomod);
if (codmod == 0){
return 1;
}
printf ("Digite a quantidade de perifericos que você precisa\n");
scanf ("%d",&qtdperi1);
cc = 0;
while (cc < qtdperi1){
pcperi = pg_peri(qtdperi1);
somaper = pcperi + somaper;
cc++;
}
if (qtdperi1 == 0){
vdperi++;
}
pctot = pcperi + precomod;
if (maior < pctot ){
maior = pctot;
}
cont++;
}
printf ("A quantidade de vendas sem peri \n%d e o maior eh de \n%.2f", vdperi, maior);
return 0;
}
Really, I realize that my code is very poorly formulated and it greatly disturbs my understanding of it. Thanks for the help, I need to understand better about this type of repetition. About the reset in while, every time I do a separate sum, I must put the null variable in that structure?
– Matheus Coelho
@Matheuscoelho I said this to be something you should think about getting better too. 'Cause a lot of times the one who’s starting ends up thinking that it has no relevance, when it has.
– Isac