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.
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\n\ RESULTADOS\n\n";
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.
#include <stdio.h> // C header. You'd better use the corresponding C++ header.
#include <iostream>
#include <cmath>
#include <iomanip>
usingnamespace 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;
}
}