In: Computer Science
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments (read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation please refer
code Images
Typed Code:
// including required headers
#include <iostream>
using namespace std;
int main()
{
// variables to store medicine in each pill
double n1, n2;
// prompt for medicine in Pill 1
cout << "Enter Number of grams of Medicine in Pill 1:
";
// reading input from user
cin >> n1;
// prompt for medicine in Pill 2
cout << "Enter Number of grams of Medicine in Pill 2:
";
// reading input from user
cin >> n2;
// A variable to store Total medicine Absorption by rabbit
double m = 0;
// variables to store Absorption of each medicine
double Absorption_n1,Absorption_n2;
// Calculating Absorption of Pill 1
// as medicine is absorbed by 60%
// multiplying n1 with 60 and dividing with 100
Absorption_n1 = ( n1 * 60)/100;
// Calculating Absorption of Pill 2
// as medicine is absorbed by 35%
// multiplying n2 with 35 and dividing with 100
Absorption_n2 = ( n2 * 35)/100;
// finding Total Absorption of Medicine
m = Absorption_n1 + Absorption_n2;
// printing the Medicine Absorption with a message
cout << "The Total Amount of Medicine of "<< m
<<" grams is absorbed by a rabbit\n";
return 0;
}
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!