### function

2. Write a function that calculates and returns the level of alcohol concentration in the blood for a person who has been drinking (BAC). There are several ways to calculate this value, but in this exercise the following formula will be used.

BAC = A/r* - 0.015*t + 0.0165

where A is the alcohol consumed, w is the mass, t time elapsed from the first drink (in hours) r constant represent the fraction of the body mass in which alcohol could be present 0.68 for men, 0.55 for women. Note that R is different for men and women, so you need an IF. to ask if the persons sex is 'F' (feminine) or 'M' (masculine) for. Assign the value to the variable R to be used in the formula: 0.55 0r 0.68 respectively.
This function is intended to calculate the BAC only, si you need to be provided (you get) the values of a, W, T and the sex of the person who has been drinking ('F' or 'M') The sex variable is CHAR.

I need help with this function
eddiekem wrote:
I need help with this function

Post what you have already programmed doing your homework for you we won't do.
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()

{

double lbs, nb, ca, t, A, w;
char sexo;

cout << " Programa para determinar riesgos en caso de\n"
<< " conducir despues de haber consumido alcohol\n\n";

cout << " Entre el peso de la persona en libras: ";
cin >> lbs;

while(lbs <= 0.0)
{
cout << "Peso invalido. Re-entre.";
cin >> lbs;
}

cout << " Entre el numero de bebidas consumidas: ";
cin >> nb;

while(nb <= 0.0)
{
cout << " Numero de bebidas consumidas invalido. Re-entre. ";
cin >> nb;
}

cout << " Entre el contenido de alcohol de una bebida en gramos: ";
cin >> ca;

while(ca <= 0.0)
{
cout << " Contenido de alcohol invalido. Re-entre.";
cin >> ca;
}

cout << " Entre el tiempo en horas que tardo en consumir las bebidas: ";
cin >> t;

while(t <= 0.0)
{
cout << " Tiempo invalido. Re-entre.";
cin >> t;
}

cout << " Entre el sexo de la persona (F = Femenino, M = Masculino): ";
cin >> sexo;

A = nb*ca; // Cantidad de alcohol consumido por una persona.
w = (10 / 2.2046) * lbs; //Conversion de libras a masa corporal en hectogramos.

cout<<"\n\nPorciento de concentracion de alcohol en la sangre: "<< BAC<< "%";

if(BAC > 0.01){
if(BAC < 0.05){
cout<<"\n===>Dificilmente el conductor se encuentra dentro de lo ilegal (pero podria complicar otras infracciones de transito).\n";
}
}
if(BAC > 0.05){
if(BAC < 0.1){
cout<<"\n===>EL conductor podria ser sujeto a arresto (a discrecion del oficial).\n";
}
}
if(BAC > 0.1){
cout<<"\n===>El conductor tendria un arresto automatico con sentencia de carcel.\n";
}

void CAS(double BAC);
{
return A / ( r * w) - ( 0.015 * t ) + 0.0165; // BAC = A / ( r * w ) - ( 0.015 * t ) + 0.0165;
}
}
 2. Write a function that calculates and returns the level of alcohol concentration in the blood for a person who has been drinking (BAC). There are several ways to calculate this value, but in this exercise the following formula will be used. BAC = A/r* - 0.015*t + 0.0165 where A is the alcohol consumed, w is the mass...
There’s no ‘w’ in the above formula.

I’ve pointed out some issues in your code by comments. I think once they are solved, the rest should come easily.
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394`` ``````#include // C header. You'd better use the corresponding C++ header. #include #include #include using namespace std; // For expert only. You'd better avoid this. int main() { double lbs, nb, ca, t, A, w; // It is usually *very* better not to declare char sexo; // any variable far from where we use them cout << " Programa para determinar riesgos en caso de\n" << " conducir despues de haber consumido alcohol\n\n"; cout << " Entre el peso de la persona en libras: "; cin >> lbs; while(lbs <= 0.0) { cout << "Peso invalido. Re-entre."; cin >> lbs; } cout << " Entre el numero de bebidas consumidas: "; cin >> nb; while(nb <= 0.0) { cout << " Numero de bebidas consumidas invalido. Re-entre. "; cin >> nb; } cout << " Entre el contenido de alcohol de una bebida en gramos: "; cin >> ca; while(ca <= 0.0) { cout << " Contenido de alcohol invalido. Re-entre."; cin >> ca; } cout << " Entre el tiempo en horas que tardo en consumir las bebidas: "; cin >> t; while(t <= 0.0) { cout << " Tiempo invalido. Re-entre."; cin >> t; } cout << " Entre el sexo de la persona (F = Femenino, M = Masculino): "; cin >> sexo; // You neglect this variable from now on A = nb*ca; // Cantidad de alcohol consumido por una persona. w = (10 / 2.2046) * lbs; // Conversion de libras a masa corporal en // hectogramos. <-- It's correct, but... // 1 pound = 4.5359237, so w = lbs * 4.5359237 cout <<"\n\n\ RESULTADOS\n\n"; // Here you're going to use the variable 'BAC', but you haven't even // declared BAC, let alone having given it a proper value: cout<<"\n\nPorciento de concentracion de alcohol en la sangre: "<< BAC<< "%"; if(BAC > 0.01){ if(BAC < 0.05){ cout << "\n===>Dificilmente el conductor se encuentra dentro de " "lo ilegal (pero podria complicar otras infracciones de " "transito).\n"; } } if(BAC > 0.05){ if(BAC < 0.1){ cout << "\n===>EL conductor podria ser sujeto a arresto (a " "discrecion del oficial).\n"; } } if(BAC > 0.1){ cout << "\n===>El conductor tendria un arresto automatico con sentencia " "de carcel.\n"; } // Here you define a function inside another function. // Move CAS() outside main(). // CAS should *not* return void: it should return double. // You need a variable in main() which receives it's returning value when // you invoke it. void CAS(double BAC); { // BAC = A / ( r * w ) - ( 0.015 * t ) + 0.0165; return A / ( r * w) - ( 0.015 * t ) + 0.0165; } }``````