I need to exit the 2nd loop after it meets the else if statement .. but how do i do that without having to enter q to exit? I will soon have to enter the conversion and a table of conversion;
if highest - lowest <= 10 increment is 1.0
if highest - lowest <= 20 increment is 5.0
if highest - lowest <= 50 increment is 10.0
if highest - lowest <= 1000 increment is 20.0
so it should look something like this ...
if i enter 1 for the lowest gallon
and 15 for the highest gallon the increment would be of 5.0
GALLONS TO LITERS
CONVERSION TABLE
Gallons Liters
======= ======
5.0 18.925
10.0 37.850
15.0 56.775
so my next question is ... how do i set up the increment ? is the formula i came up with right ? because if i put 1 = lowest gallon and 10 = highest gallon it would be ...
GALLONS TO LITERS
CONVERSION TABLE
Gallons Liters
======= ======
1.0 3.785
2.0 7.570
3.0 11.355
4.0 15.140
5.0 18.925
6.0 22.710
7.0 30.065
8.0 30.280
9.0 34.065
10.0 37.850
with an increment of 10.0 ... keep in mind the increment does not go over 20.0
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 58 59 60 61 62 63 64
|
#include <iostream>
#include <iomanip>
using namespace std;
int
main ()
{
double
highGallons = 0,
lowGallons =0,
hiGallons = 0 ,
loGallons = 0;
char charVal;
bool quitting;
quitting = false;
cout << "This program creates a gallons to liter conversion table." << endl;
do {
cout << "\nEnter the lowest gallon value to display <q to quit>: ";
cin >> lowGallons;
if (cin.fail())
{
cin.clear();
cin >> charVal;
if (charVal == 'q')
quitting = true;
else cout << "You entered an illegal character: ("
<< charVal << ")" << endl;
}
else if (lowGallons >= 0 and lowGallons <=1000)
{
do
{
cout << "\nEnter the highest gallon value to display <q to quit>: ";
cin >> highGallons;
if (cin.fail())
{
cin.clear();
cin >> charVal;
if (charVal == 'q')
quitting = true;
else cout << "You entered an illegal character: ("
<< charVal << ")" << endl;
}
else if (highGallons >=0 and highGallons <=1000) ;
{
hiGallons = highGallons * 3.785 ;
loGallons = lowGallons * 3.785 ;
/*cout << loGallons;
cout <<hiGallons;*/
}
} while (!quitting);
}
} while (!quitting);
cout << "\nAborting; no conversion performed" << endl;
cin.ignore();
cin.get();
return(0);
}
| |