Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std; //Always include in C++ programming.
- int main() // Always include in C++ programming.
- {
- char answer; // answer variable defined as a character.
- int month = 0; // defining months as an integer for my while loop.
- float effectiveness = 100.00; //drug effectiveness starts at 100. I am starting off the value as 100 and then it will decrease time over time.
- float drug_potency_loss, target_effectiveness; // defining my variables as a float.
- do { //start do loop
- effectiveness = 100.0;
- month = 0;
- // I had to put my variables again bc the do loop runs the whole code once, otherwise it won't work properly as expected.
- cout << "Enter drug potency loss % and target effectiveness %: "; // cout statement tells the user to enter the input.
- cin >> drug_potency_loss >> target_effectiveness; // cin statement allows the user to enter the input.
- cout << "You entered potency loss = " << drug_potency_loss << "% " << "and Target effectiveness = " << target_effectiveness << "%" << endl; //cout statement tells the user that they entered the potency loss and the target effectiveness.
- cout << "" << endl; //this creates a blank line.
- if ((drug_potency_loss < 100 && drug_potency_loss > 0) && (target_effectiveness > 25 && target_effectiveness < 100)) {
- cout << "Potency loss = " << drug_potency_loss / 100.00 << endl; // This will calculate the potency loss in decimal numbers instead of percentage numbers.
- cout << "Target effectiveness = " << target_effectiveness << endl; // cout statement tells the user the target effectiveness.
- cout << " " << endl; //creates a blank line.
- cout << "Determining drug effectiveness: ..." << endl; // cout statement.
- cout << "" << endl; // blank line.
- }
- while (effectiveness + 1 > target_effectiveness) { // A while loop. The loop will pretty much stop whenever the drug effectiveness is LESS than the target effectiveness.
- // I had to add the +1 in order for it to show the last result for the drug effectiveness whenever the loop works, otherwise it won't include the next month.
- if (drug_potency_loss < 0) {
- cout << "Drug potency cannot be negative, please renter: ";
- cin >> drug_potency_loss;
- // If the user enters a number less than 0, it will tell the user to renter another number (potency loss)
- }
- if (drug_potency_loss > 100) {
- cout << "Drug potency has to be < 100%, please renter: ";
- cin >> drug_potency_loss;
- // If the user enters a number greater than 100, it will tell the user to renter another numnber (potency loss)
- }
- if (drug_potency_loss == 100) {
- cout << "Drug potency has to be < 100%, please renter: ";
- cin >> drug_potency_loss;
- }
- else if (drug_potency_loss == 0) {
- cout << "Drug has 0% potency loss, it will not expire" << endl;
- break; // Out of all methods, I HAD to use a break statement in order for this particular part to work.
- // if the drug potency loss is == 0, the cout statement will show and the break statement will stop it from going to an infinite loop.
- //It will then direct the user if they want to do the program again.
- }
- else if (target_effectiveness < 25) {
- cout << "Effectiveness cannot be < 25%, please renter: ";
- cin >> target_effectiveness;
- // If the user enters a number less than 25, it will tell the user to renter another number (target effectiveness)
- }
- if (target_effectiveness >= 100) {
- cout << "Effectiveness cannot be >= 100%, please renter: ";
- cin >> target_effectiveness;
- // If the user enters a number greater than 100, it will tell the user to renter another number (target effectiveness)
- }
- if (target_effectiveness == 100) {
- cout << "Effectiveness cannot be >= 100%, please renter: ";
- cin >> target_effectiveness;
- // If the user enters 100, it will tell the user to renter another number (target effectiveness)
- }
- if (target_effectiveness != 0) { // If the user ignores all the previous statements above, then the loop proceeds to do it's calculation,
- // and predicts when the drugs will expire according to months.
- effectiveness = effectiveness - (effectiveness * (drug_potency_loss / 100.00)); // This is the equation in order to calculate the drug effectiveness within the loop.
- cout << "For month " << month << " drug effectiveness is " << effectiveness << endl; // cout statement within the loop.
- // It will repeat until the drug effectiveness is les than the target effectiveness.
- month++; // Month++ adds the months starting from 0 until the drug effectivess is less than the target effectiveness.
- }
- }
- // puts this statement in here.
- if (drug_potency_loss > 0 && drug_potency_loss < 100 && target_effectiveness > 25 && target_effectiveness < 100)// This will make sure the bottom output will not show if the user enters the drug potency loss = 0.
- {
- cout << "" << endl; // Creates a blank line.
- cout << "Drug will be below its target effectiveness in " << month - 1 << " months and should be discarded." << endl;
- }
- // cout stattement.
- // I had to add month - 1 in order for it to tell the user the correct month. If I didnt do month - 1, it will give the user the wrong month.
- cout << "" << endl; // this creates a blank line
- cout << "Do you want to run the program again? Enter (y/n): "; // cout statement tells the user if they want to run the program again.
- cin >> answer; // the user enters y or n if they want to run the program again.
- cout << "" << endl;
- } while (answer == 'y' || answer == 'Y'); //end do loop
- cout << "End Program" << endl; // cout statement if they say n.
- return 0; // return statement ends function.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement