"humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 24 hours. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.2lf", yourValue);"

Respuesta :

The question is incomplete! Complete question along with code and step by step explanation is provided below.

Question:

Caffeine levels A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-life of about 6 hours in humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 18 hours. Output each floating-point value with two digits after the decimal point, which can be achieved as folllows: printf("%0. 21f", yourValue); Ex: If the input is 100 the output is: After 6 hours: 50.00 mg After 12 hours: 25.00 mg After 18 hours: 12.50 mg

Explanation:

#include <stdio.h>

int main()

{

   float caffeine;  // variable to store the amount of caffeine from the user

   float after_6, after_12, after_18;  // variables to store the results

   printf("Enter caffeine amount in mg: ");

   scanf("%f", &caffeine);  //ask user to input the amount of caffeine

// calculate the half life by dividing the caffeine amount by 2

   after_6=caffeine/2;  

   after_12=after_6/2;  // divide the current half life (after_6) again by 2

   after_18=after_12/2;  // divide the current half life (after_12)  again by 2

// print the half life after 6, 12, and 18 hours

// ".2" is used to display 2 digits after the decimal point

   printf("after 6 hours in mg: %.2f", after_6);

   printf("\nafter 12 hours in mg: %.2f", after_12);

   printf("\nafter 18 hours in mg: %.2f", after_18);

   return 0;

}

Output:

Enter caffeine amount in mg: 200

after 6 hours in mg: 100.00

after 12 hours in mg: 50.00

after 18 hours in mg: 25.00

Ver imagen nafeesahmed

Answer:

Input: 100

caffeine_mg = float(input())

after_6 = caffeine_mg / 2

after_12 = after_6 / 2

after_24 = after_12 / 4

print(f'After 6 hours: {after_6:.2f} mg')

print(f'After 12 hours: {after_12:.2f} mg')

print(f'After 24 hours: {after_24:.2f} mg')

Explanation:

#Input

100

#define caffine mg with float input // for decimal

caffeine_mg = float(input())

#define after 6, after 12, after 24 divided by value

after_6 = caffeine_mg / 2

after_12 = after_6 / 2

after_24 = after_12 / 4

#print format.str { after x: . value } mg

print(f'After 6 hours: {after_6:.2f} mg')

print(f'After 12 hours: {after_12:.2f} mg')

print(f'After 24 hours: {after_24:.2f} mg')