3.14 LAB: Input and formatted output: 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 24 hours. Use a string formatting expression with conversion specifiers to output the caffeine amount as floating-point numbers.

Respuesta :

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

double caffeineMg;

cin>>caffeineMg;

cout<<"After 6 hours: "<<fixed<<setprecision(2)<<caffeineMg/2.0<<" mg\n";

cout<<"After 12 hours: "<<fixed<<setprecision(2)<<caffeineMg/4.0<<" mg\n";

cout<<"After 24 hours: "<<fixed<<setprecision(2)<<caffeineMg/8.0<<" mg\n";

return 0;

}

Explanation:

  • Declare a variable for caffeine and take the input from user.  
  • Print the results by dividing the caffeine by relevant Half Life.
  • Use setprecision function to display the result up to 2 decimal places.

The program is a sequential program, and does not require loops or conditional statements.

The program in Python, where comments are used to explain each line is as follows:

#This gets input for the Caffeine Amount

caffeineMg = float(input("Caffeine Amount: "))

#This prints the amount after 6 hours

print("After 6 hours: {:.2f}". format(caffeineMg/2.0))

#This prints the amount after 12 hours

print("After 12 hours: {:.2f}". format(caffeineMg/4.0))

#This prints the amount after 24 hours

print("After 24 hours: {:.2f}". format(caffeineMg/8.0))

Read more about sequential program at:

https://brainly.com/question/17970226