jeudi 25 mai 2017

Why the function retornaFacturacio is not calculating the cost? Help please

This is the code where i have an array of int in which the column 0 is a kind of numeric code, column 1 is the quantity of cars with gas motor, column 2 for the quantitiy of car with diesel motor and column 3 for the quantity of hybrid cars. so this is a garage where the function retornaFacturacio return u the value of the total cost u have to pay IF the numer of cars of gas motor(column 1) is the same to the numer of cars of diesel (column).

And the problem i m getting is that in the cout of retornaFacturacio i m getting the value 0 and i dont know why..

#include <iostream>
using namespace std;

void leermatriu (int (&talleres)[100][4]);
int retornaFacturacio(int talleres[100][4]);

int main(){
int talleres[100][4];

leermatriu(talleres);
retornaFacturacio(talleres);
//return retornaFacturacio(talleres);

}

void leermatriu(int (&talleres)[100][4]){
int numTalleresLoc;
int codigoTallerloc, gasolinaLoc, dieselLoc, hibridosLoc;
cout<<"cuantos talleres desea facturar?"<<endl;
cin>>numTalleresLoc;

for(int i=0;i<numTalleresLoc;i++){
cout<<"Introduzca el codigo de taller, cantidad de coches de gasolina, diesel y hibridos."<<endl;   
    for(int j=0; j<4;j++){

        cin>> talleres[i][j];

    }
}
}

int retornaFacturacio(int talleres[100][4]){
int cantMotor, cantGasolina;
int taller;
int precio;
for(int i=0;i<100;i++){
    for(int j=0; j<4;j++){
        if(talleres[i][1]==talleres[i][2]){
            taller = talleres[i][0];
            cantMotor = talleres[i][1];
            cantGasolina = talleres[i][2];
        }
    }
}
precio = cantMotor*150+cantGasolina*200;
cout<<"tiene que pagar "<< precio <<" euros para el taller " << taller;

return precio;
}

I just want to calculate the value of precio and show it in that cout with the value of taller.

Aucun commentaire:

Enregistrer un commentaire