-
Notifications
You must be signed in to change notification settings - Fork 0
/
Radioactive Decay
57 lines (29 loc) · 1.11 KB
/
Radioactive Decay
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
/* This program computes the amount of a radioactive substance
remaining after an initial amount decays for some time period.
Written by zayad sada -- Project -- jun. 24, 2024
Input: element's name, its half-life, the initial amount,
and a time period
Output: the input items and the amount of the substance
remaining at the end of the time period
--------------------------------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
#include <string> // string
#include <cmath> // pow()
using namespace std;
int main()
{
cout << "Enter the name of your radioactive substance: ";
string element;
cin >> element;
cout << "and its half-life (days): ";
double halfLife;
cin >> halfLife;
cout << "Enter the initial amount (mg) and a time period (days): ";
double initialAmount, time;
cin >> initialAmount >> time;
double amountRemaining = initialAmount * pow(0.5, time / halfLife);
cout << "\nFor " << element
<< " with half-life " << halfLife << " days\n"
<< initialAmount << " mg" << " will be reduced to "
<< amountRemaining << " mg after " << time << " days\n";
}