I need to make a program that:
- Get the pc model, the price of it and display the highest value, plus the number of computers without peripherals.
- In the main function, receive the amount of peripherals.
- A function that receives as a parameter the amount of peripherals, sum the prices of them.
- Display the number of sales without additional peripherals and the value of the highest sales.
However, at the time of displaying the highest value, it goes out wrongly.
Below, the code you've made.
#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;
}