So either I'm retarded or this do-while loop should terminate, but it loops when the condition is true and false. Bolded text is the while loop condition check.
Check it:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <ctime>
using namespace std;
void simulation ()
{
// for loop with number of iterations = 10
}
int main ()
{
srand (time(0));
string operation;
cout << "Using the letters 'o', or 'q', please indicate if you would like to simulate once, or quit the program: " << endl;
cin >> operation;
string reservoir_name; // Creating variables for reservoir
double reservoir_capacity;
double outflow;
double inflow_min;
double inflow_max;
if (operation == "q")
{
cout << "Exiting program." << endl;
system ("pause");
return 0;
}
while (operation == "o") // Choose one or multiple simulations.
{
if (operation == "o") // For one simulation
{
string reservoir_name; // Creating variables for reservoir function
double reservoir_capacity;
double outflow = 0;
double inflow_min = 0;
double inflow_max = 0;
double inflow_range = inflow_min + inflow_max;
double inflow_threshold = .9 * inflow_range/2; // Math for acceptable flow threshold.
do
{
cout << "What is the name of the reservoir?" << endl;
cin.ignore ();
getline (cin,reservoir_name); // Grab whole string for reservoir name.
cout << "What is the capacity of the reservoir in MAF (Millions of Acre Feet)?" << endl;
cin >> reservoir_capacity;
cout << "What is the minimum inflow?" << endl;
cin >> inflow_min;
cout << "What is the maximum inflow?" << endl;
cin >> inflow_max;
cout << "What is the required outflow?" << endl;
cin >> outflow;
inflow_range = inflow_min + inflow_max;
inflow_threshold = .9 * inflow_range/2;
cin.ignore ();
if (outflow > inflow_threshold) // Check for unacceptable outflow levels.
{
cout << "Warning! The outflow is over 90% of the average inflow. Simulation aborted. Please enter a value that is less than 90% of average inflow." << endl;
}
}while (outflow > inflow_threshold );
}
}
simulation ();
system ("pause");
return 0;
}
Log in to comment