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\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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>  // C header. You'd better use the corresponding C++ header.
#include <iostream>
#include <cmath>
#include <iomanip>

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;
    }
}

Registered users can post here. Sign in or register to post.