Answer:
// C++ program.
#include <bits/stdc++.h>
using namespace std;
// main function
int main() {
// variable
float n;
cout<<"Enter the initial value:";
//User input
cin>>n;
//Variables for measurements at 6, 12, and 18 hours
float hours_6, hours_12, hours_18;
//Set floating-point precision
cout << fixed;
cout << setprecision(6);
//Calculate caffeine amounts after 6, 12, 18 hours
hours_6 = n / 2.0;
hours_12 = hours_6 / 2.0;
hours_18 = hours_12 / 2.0;
//Display results
cout<<"After 6 hours: "<<hours_6<<"mg"<<endl;
cout<<"After 12 hours: "<<hours_12<<"mg"<<endl;
cout<<"After 18 hours: "<<hours_18<<" mg"<<endl;
return 0;
}
Explanation:
The program reads input from the user and sets the output precision to six decimal places. The caffeine amount after 6 hours is half the initial input. At 12 hours, it is half the 6-hour value, and after 18 hours, it is half the 12-hour value.
Output:
Enter the initial value:100
After 6 hours: 50.000000 mg
After 12 hours: 25.000000 mg
After 18 hours: 12.500000 mg