TresKom was hired by the previous government to account for expenses in the Chol
ID: 3832899 • Letter: T
Question
TresKom was hired by the previous government to account for expenses in the Choliseo VIP lounge. The new government of the republic, made up of engineers with impeccable behavior wants to improve the code of TresCom engineers. However, the TresCom engineers were so inept that they did not create functions and put all the code in the main. We hope you do the work as it should have been done in the beginning!
1. In the PrintComilonayTotal function, in addition to printing the comilonas, you must calculate and print also the total amount of money spent on the comilonas (the total).
CODE
//3Com.Enaudi.inc todos los torcidos corruptados
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
bool verificaMemory(float*);
void readComilona(float*, int);
void PrintComilonayTotal(float*, int);
int main() {
float *gastos;
int numOfgastos;
cout << "Entre el numero total de fiestas: ";
cin >> numOfgastos;
gastos = new float[numOfgastos];
if (!verificaMemory(gastos))
return -1;
cout << "Entre la factura de su comilona corrupta ";
readComilona(gastos, numOfgastos);
//Display gastos to verify they are inside the computer
PrintComilonayTotal(gastos, numOfgastos);
delete[] gastos;
return 0;
system("pause");
}
bool verificaMemory(float* gastos)
{
if (gastos == NULL) {
cout << "Eror allocating memory, bye!!!";
return false;
}
else
return true;
}
void readComilona(float* gastos, int numOfgastos)
{
for (int i = 0; i < numOfgastos; i++) {
cout << "Leyendo Comilona " << i + 1;
cout << " en posicion de memoria: " << gastos + i << " : ";
cin >> *(gastos + i);
}
}
void PrintComilonayTotal(float* gastos, int numOfgastos)
{
float sumComilonas = 0.0f;
for (int i = 0; i < numOfgastos; i++) {
cout << " Comilona numero " << i + 1;
cout << " en direccion de memoria: " << gastos + i;
cout << " con valor de: ";
cout << *(gastos + i);
sumComilonas += *(gastos + i);
}
cout << " Sum : " << sumComilonas << endl;
system("pause");
}
Explanation / Answer
Hi Firends, Your program is already written to print total comilonas.
Can you clarify your need ?
In case of any issue, please comment
void PrintComilonayTotal(float* gastos, int numOfgastos)
{
float sumComilonas = 0.0f;
for (int i = 0; i < numOfgastos; i++) {
cout << " Comilona numero " << i + 1;
cout << " en direccion de memoria: " << gastos + i;
cout << " con valor de: ";
cout << *(gastos + i);
// adding the current comilonas in total
sumComilonas += *(gastos + i);
}
cout << "Total comilonas : " << sumComilonas << endl; // printing total
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.